I don't understand why it does not kill me.
function Touched(hit) --"Touched" is name of the function. local hum = hit.Parent:findFirstChild("Humanoid") if hum then hum.Health = 0 end end script.Parent.Touched:connect(Touched)
function Touched(hit) local parent = hit.Parent if game.Players:GetPlayerFromCharacter(parent) then parent.Humanoid.Health = 0 end end script.Parent.Touched:connect(Touched)
alternative for only players not npc's
To make things easier, just have the function be triggered at the beginning.
script.Parent.Touched:connect(function(hit) local humanoid = hit.Parent:WaitForChild("Humanoid") . if humanoid then humanoid.Health = 0 end end
I prefer using a WaitForChild when I'm using a script that requires something to be found before the following code should be ran.