Way to keep specific item in player's inventory on death?

I am making hats for my server (with custommodeldata and a carved pumpkin) and was wondering how I can make it so a player will keep the item on death? both when worn or in inventory. Thank you
Was this page helpful?