script.Parent.Touched:Connect(function(hit) if hit and hit.Parent.FindFirstChild("Humanoid")then hit.Parent.Humanoid.Health = 0 end
end)
i need help with this code because when i jump on it, it doesnt kill me
script.Parent.Touched:Connect(function(hit) if hit and hit.Parent.FindFirstChild("Humanoid")then hit.Parent.Humanoid.Health = 0 end
end)
i need help with this code because when i jump on it, it doesnt kill me
Just an add on to the above but explaining a little more about which does what
script.Parent.Touched:Connect(function(hit) --connect a function to when the block is touched
local humanoidcheck = hit.Parent:FindFirstChild("Humanoid") --make sure this is a player and not some random object
if humanoidcheck ~= nil then --if humanoid is not equal to nil (non existing) then
humanoidcheck.Health = 0 --kill the player
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
hit.Parent.Humanoid.Health = 0
end
end)
You just had a slight error in where you placed the " : " on :FindFirstChild().
You probably had something like, "FindFirstChild is not a member of hit" in your errors output.
No problem.
This discussion is preserved as it was. New answers, comments, and votes are closed.
6 comments
Where is the script located?
it is located right under the part so the part is the 'Parent'
I mean you could test it
i did and im not dying
So no...
Try and remove the 'If Hit and' part