✓ Accepted answer
You're checking the script's parent for the humanoid, instead of the "part". part in this case is what touched the script's parent, so that's the object we would search the humanoid for.
Try this:
function onTouch(part)
local Guy = part.Parent:findFirstChild("Humanoid")
if (Guy == nil) then return end
Guy.Health = 0
end
script.Parent.Touched:connect(onTouch)
We could even clean this up a bit, not that it would make much of a difference:
script.Parent.Touched:connect(function(Part)
local Human = Part.Parent:FindFirstChild'Humanoid'
if Human then
Human.Health = 0
end
end)
However, this is just how I'd write it. You don't need to worry to much about small details, but for the sake of readability, I'd prefer something like this.
3 comments
It still doesn't work
The problem is that you need to specify part.Parent.Humanoid rather than script.Parent.Humanoid. The == nil part is correct.
shouldn't it be "part.Parent:findFirstChild("Humanoid")"