How would I update a player's character after his death?

I made this script for the player to take damage when a Zombie touches it.
script:

game.Players.PlayerAdded:Connect(function(plr)
	local charac = 	 plr.Character or plr.CharacterAdded:Wait()
	local hum = charac.Humanoid
	local db = false
	hum.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Zumanoid") then
			if db == false then db = true
			
			hum:TakeDamage(5)
			if hum.Health <= 0 then
			
             charac = plr.CharacterAdded:Wait()
		     hum = charac.Humanoid	
		end
		db = false
		end
		end
	end)
end)

The problem is that the function stops working after the player dies
I tried to update the Player Character, but it didn’t work
Can someone help me?

Add a character added function after the player added function, so that the code will run whenever the character has respawned.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)

    end)
end)
1 Like