What does "attempt to index nil with 'WaitForChild'" mean?

script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Pencil") local price = 350 local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if stats.Strength.Value>=price then stats.Strength.Value = stats.Strength.Value - price local cloned = item:Clone() cloned.Parent = player.Backpack cloned.Parent = player.StarterGear end end) 

I am trying to make a shop and it comes up with "attempt to index nil with 'WaitForChild'" on line 6:

local stats = player:WaitForChild("leaderstats") 

I copied it exactly how the video had it and the video had no problem and apparently player has no value even though we set it up just one line above

1

1 Answer

It means that you are indexing a nil value, which means that player value is nil, which means that game.Players.LocalPlayer on the previous like returns nil. Why that is you need to figure out, as there is not much to go by.

The example shows that it should be local player = game:GetService("Players").LocalPlayer, so you may want to try that.

1

You Might Also Like