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'?? (SLOVED BY ME)

Asked by 4 years ago
Edited 4 years ago

I made this basic script and it keeps saying Attempt to index nil with 'Humanoid' Help please

game.Players.PlayerAdded:Connect(function(plr)
    plr.Character.Humanoid.Health = 0
end)

2 answers

Log in to vote
0
Answered by 4 years ago

All I had to do was this:

game.Players.PlayerAdded:Connect(function(plr) wait(0.01) -- Add this plr.Character.Humanoid.Health = 0 end)

0
Why not plr.Character:WaitForChild("Humanoid").Health = 0? It will yield until Humanoid exists cherrythetree 130 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

When you try to find Humanoid you need to wait till the players connect and load. So yea adding a wait would fix the problem because scripts load first.

Answer this question