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)
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
Did not work
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.
you could use the same code as the dreaded "kill brick"
That will not help him find the solution to his problem. He's wanting the script he already has fixed.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
Script works on my end, are you getting any errors? In studio tell us any errors related to the script from the output or in game hit F9 and tell us any errors related to the script from there.
Make sure the script is inside the part you want to kill the player
I tested the script seems to work perfectly fine. Are sure the script you're using isn't disabled or even using a Local Script. The only other reason I could think of for the script not to work is if a third party script renames the Humanoid.
OMG!! It is disabled :P