Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index nil with 'Humanoid'?

I tried this part of a script: if game.Players.LocalPlayer.Character.Humanoid.Health == 1 then

The script is called HealthCheck.

And it gave me the error: Players.(username).PlayerScripts.HealthCheck:1: attempt to index nil with 'Humanoid'

1 comment

0

is it normal script or local script?

3 answers

Perhaps the character hasn't loaded in yet, maybe wrap it in a CharacterAdded() function then do :WaitForChild("Humanoid")

Try doing

if game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Health == 1 then

Normally the player isn't Humanoid until they load in, so you need the :WaitForChild("Humanoid"). Hope this helped

Again. Players.(player).PlayerScripts.HealthCheck:1: attempt to index nil with 'WaitForChild' Edit: now there's no error, but it won't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.