WaitForChild, FindFirstChild, etc randomly being indexed with nil when calling the player characters Humanoid

Im trying to write a power box task system for a game and im at a loss since this is happening with zero explanation
image

really not sure whats going on here, cause i have WaitForChild around 8 other times in this script and they all work perfectly fine. just specifically here

image

ive checked it multiple times, rewritten this section to the same outcome where it indexes with nil every time i run it. its the same method ive always used too so idk why its not working specifically when calling the player characters humanoid

seems to only happen with this humanoid call, and seeing another instance of this exact piece of code in another, months older project works perfectly fine

restarting studio also does nothing to fix this


nvm, i just had to add a Plr.CharacterAdded:Wait()

dont get why though cause there was nothing in the output stating that the players character was a nil value, and doing just what i wrote worked every time up until there

The character probably didn’t load yet, therefore Char is nil. The character does not load immediately.

Try defining your Char variable as local Char = Plr.Character or Plr.CharacterAdded:Wait()

2 Likes

Mark @xyrafrost answer as the solution.

I have years of experience with this to know it’s the correct answer :slightly_smiling_face:

you assumed they had a character, you need to wait for it to load.