#why this script isn't working
18 messages · Page 1 of 1 (latest)
I think this can help you:
The parameter passed in the touched event is otherPart, that is, what part has touched the BasePart that contains the script right
thing is
here
Uh
you're saying that the part has a humanoid
oh lol
part.Parent is just the workspace.
Solution?
pass the otherpart
make an if statement that voids the function if the humanoid is not found
wait a second
local part = script.Parent
part.Touched:Connect(function(otherPart) --< Here, otherpart is the parameter, you need to search tutorials on lua about parameters and arguments if you don't know.
local humanoid = otherPart.Parent:FindFirstChild("Humanoid") --< we get the humanoid based on the OtherPart parent (Character)
if not humanoid then return end --< if the line above doesn't find "Humanoid", that is, the other part wasn't a character instance child, exit the function
humanoid.Health = 0 --< set the health
end)
@void mist
Alr thanks