function kill(victim) victim.Parent.Humanoid.Health=0 end script.Parent.Touched:connect(kill)
My question is why it kills only one time then says "Disconnected event because of exception." Is it because there's not an if-then statement in there?
Try this instead:
function kill(victim) if victim.Parent:FindFirstChild("Humanoid") ~= nil then victim.Parent.Humanoid.Health = 0 end end script.Parent.Touched:connect(kill)
Here's the more common version:
function onTouched (part) local h = part.Parent:findFirstChild("Humanoid") if(h~=nil)then h.Health = 0 end end script.Parent.Touched:connect(onTouch)
EDITED! Should work
This should work
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then -- if a humanoid exists, then humanoid.Health = 0 -- damage the humanoid end end script.Parent.Touched:connect(onTouch)