hey there so I'm making a game and a sell area for points ok? so when i touch the brick my script is:
script.Parent.Touched:Connect(function() if game.Players.LocalPlayer.leaderstats.Potatoes.Value == 6 then game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value +10 end end)
and it get this error:Attempt to index nil with leaderstats
First, make this a server script, it won't work if it's a local script. (I also did getplayerfromcharacter because you cant get a localplayer from a server script.)
Second, use waitforchild just in case the leaderstats hasn't loaded yet!
edited code:
script.Parent.Touched:Connect( function(hit) local Player = game.Players.GetPlayerFromCharacter(hit.Parent) if Player:WaitForChild("leaderstats"):WaitForChild("Potatoes").Value == 6 then Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10 end end )
Accept answer if it works.
Closed as Not Constructive by EzraNehemiah_TF2
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?