I was going to do this script just to kill the zombies, but when I touch the part, I die. How do I make sure that both me and other players don't die when they get into it?
part.Touched:Connect(function(p) if p.Parent:FindFirstChildOfClass("Humanoid") then local plr = workspace[p.Parent.Name] wait(1) plr.Humanoid.Health = plr.Humanoid.Health - 20 wait(0.1) part:Destroy() end end)
You can rename zombie humanoid to "Zombie" and find the Humanoid by it's name.
Here's the code:
part = script.Parent debounce = false part.Touched:Connect(function(p) if debounce == true then --check for cooldown debounce = false --cooldown on local hum = p.Parent:FindFirstChildOfClass("Humanoid") --find humanoid from the touched event if hum.Name == "Zombie" then --check if humanoid name is a zombie hum:TakeDamage(20) wait(1) --interval debounce = true --cooldown off -- part:Destroy() end end)