function onTouched(hit)
local Humanoid = hit and hit.Parent:FindFirstChild("Humanoid")
local Head = hit and hit.Parent:FindFirstChild("Head")
if Humanoid and Head and Head:IsA("BasePart") then
Humanoid.Health = 0
end
end
:FindFirstChild() - Finds the object you're looking for; returns a boolean value, indicating its existence.
:IsA - Decides whether the object is the given class name you want it to be; returns a boolean value, indicating if the object is the class name you're looking for.
Take note that an object's property can not be adjusted directly:
local Health = hit.Parent.Humanoid.Health
Health = 0
You're just setting the value to 0, not the property. As you can see from the function I've edited, I changed the property by the Humanoid object variable, rather than the value.
local Humanoid = hit and hit.Parent:FindFirstChild('Humanoid")
--
Humanoid.Health = 0
1 comment
Thanks! I am smarter now because of you xD