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?