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

Attempt to index nil with 'Humanoid'?

Asked by 4 years ago
Edited 4 years ago

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'

0
is it normal script or local script? Friskyman321 121 — 4y

3 answers

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago
Edited 4 years ago

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

Ad
Log in to vote
0
Answered by
Ghost40Z 118
4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question