Script stops working when trying to WaitForChild("Humanoid")

Hello,
My script, which is inside a tool, stops working whenever I try to create a variable for humanoid to play some animations.

image

For some time I was able to stop the bug by putting the variables into a tool.Equipped function like this

image

But the next day when I try to play animations it stops and gives me this


and the entire script stops and nothing works

I tried using using different methods but none of them worked

3 Likes

Have you tried defining the humanoid before the tool.Activated function

2 Likes

I have but it says “Attempt to index nil with WaitForChild”

2 Likes

This means that it can’t find the character, did you define that outside and before the humanoid?

1 Like

Yes, here is the code for the variables
image

1 Like

Try doing player.Character or player.CharacterAdded:Wait() when defining the char variable

2 Likes

Is the script a LocalScript or a regular script?

1 Like

Its a local script located in a tool

its a local script because if it wasnt then local player wouldnt have been found and wouldve errored

1 Like

Actually that isn’t exactly neccessary it’s better to define it outside of the tool rather then retrieve them every time the player activates the tool

1 Like

This worked! Thank you I used the player.CharacterAdded:Wait()

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.