Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

this script attempt to index nil? how can I fix this?

Asked by 3 years ago
Edited 3 years ago

I get an error attempt to index nil. how to fix this?

server sided script:

local player = game.Players.LocalPlayer

if player.leaderstats.Value.Money > 12000 then
player.leaderstats.Value.Money = player.leaderstats.Value.Money - 12000
player.PlayerGui.ScreenGui.TextLabel.Text = "Purchased!"
end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Try:

player = game.Players.PlayerAdded:Connect(function(player)

if player.leaderstats.Value > 12000 then
player.leaderstats.Value = player.leaderstats.Value -12000
player.PlayerGui.ScreenGui.TextLabel.Text = "Purchased!"

end)

LocalPlayer cannot be used on a server sided script, only local.

If I helped, please mark this answer as solved! We both will get a reward!

Ad

Answer this question