How do ONLY run a function if the player is alive

I want it so the player is given some items and when the player dies they get the items back. Currently it gives the player the items before they respawn and after spawning the items are deleted. I'm on 24w21b
Continue to help post