Here's the script:
wait() function onTouched(part) local h = part.Parent:FindFirstChild("Humanoid") local anim = h:LoadAnimation(script.anim) if h~=nil then wait(.05) h:TakeDamage(5) anim:Play() end wait(1) end script.Parent.Touched:connect(onTouched)
The animation part doesn't work but without it the script works perfectly, have i done anything wrong?
Here's a joke:
The patient says: "It hurts when I raise my arm like this." Then the doctor says: "Then don't raise your arm like that".
If it says h is a nil value, it's a nil value.
Apparently, at line 5 part.Parent:FindFirstChild("Humanoid")
is being ran before the Humanoid exists.
Try using WaitForChild()
instead of FindFirstChild()
so it'll wait until the object is there.
But if you still want to use FindFirstChild()
, you can run h:LoadAnimation()
AFTER you check if the h is not nil (if h~=nil then
).