I'm just trying to make a single lava brick and this script won't work for some reason.
function onTouch(part) local Guy = script.Parent:findFirstChild("Humanoid") if (Guy == nil) then return end Guy.Health = 0 end script.Parent.Touched:connect(onTouch)
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) -- checking "part.Parent" for humanoid 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:
-- Create the function in the process of declaring the event. script.Parent.Touched:connect(function(Part) local Human = Part.Parent:FindFirstChild'Humanoid' if Human then -- This will return true if humanoid was found. 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.
function onTouch(part) local Guy = script.Parent:findFirstChild("Humanoid") if (Guy ~= nil) then return end Guy.Health = 0 end script.Parent.Touched:connect(onTouch)
you used == nil which would mean it doesnt exist but ~= means it does.