Hello there. I'm making a shop system and when I do a if stament to see if the player has enough money to buy the item it gives me this error.
workspace.Apple.Script:2: attempt to index nil with "leaderstats"
Here's the code I'm using
script.Parent.ClickDetector.MouseClick:Connect(function() if game.Players.LocalPlayer.leaderstats.Money.Value >= 3 then -- heres the part im talking about game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - 3 -- dont worry its just the text doing that end end)
also this for somereason
game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - 3 -- sorry, the text did that
LocalPlayer doesn't exist on the server so it's returning nil (hence the error). The MouseClick event has a parameter which is the player that clicked it, use that instead.
Try using :FindFirstChild('leaderstats') or :WaitForChild('leaderstats') Maybe that'll work.