Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix "attempt to index nil with WaitForChild"?

Asked by
Jec0be 11
3 years ago

I am trying to make a script where it includes the humanoid. I made it as a local "local humanoid = player:WaitForChild("Humanoid")". Player is a local = game.Players.LocalPlayer. What am I doing wrong

0
You are trying to find the Humanoid from the Player. The Humanoid is located in the Player's Character, so since there is no Humanoid located in the player, it will return nil. Just change it to player.Character:FindFirstChild("Humanoid") and it will work. RazzyPlayz 497 — 3y
0
Looks like that's a server script LakasoOscar 0 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Yeah, you're trying to get the humanoid from the player when it's a child of the character. Also, make sure this is a localscript as game.Players.LocalPlayer doesn't work on the server.

local player = game.Players.LocalPlayer
local character = player.Character

if character then --You want to make sure the player currently has a character
    local humanoid = character:FindFirstChild("Humanoid") 
    --It's better to use findfirstchild so it doesn't return an error if it's not found
end
0
It is a local script. Thank you, I figured that a few minutes later. And thanks for telling me about the one to find the character. Jec0be 11 — 3y
Ad

Answer this question