Attempt to index nil with "WaitForChild"

Ive been making a codes system where it rewards you with coins.
But an error pops up saying:
error
Here is part of the script
script
And its in a Normal Script:
Location
Im new to scripting so help would be appreciated!

1 Like

It’s because you can’t get the localplayer in a serverscript, you can only do it in local scripts, and also you have accidently typed :Wa?
image

1 Like

oh ok how would you access player in normal script

1 Like
game.Players.PlayerAdded:Connect(function(Player)

end)

This gonna work all times a player enter the game, and the Player value is the player.

1 Like

thanks ill try it . . . . . . .

1 Like

local player doest work with a normal script try a local script and put him on Starter Player Scripts

1 Like

Its always nil on server script

If you dont want it a local script just do this

Game.Players.PlayerAdded:Connect(function(plr)
  local LS = plr:WaitForChild(leaderstats)
    if LS then
       local coins = LS:WaitForChild(coins)
       local rubbies = LS:WaitForChild(rubbies)
       local codes = {infCoins = coins.Value == coins.Value + 10000000 }
    end
end)
1 Like

Everyone before you missed this bruh :slight_smile:

1 Like

I did many mistakes In this script but I edit it