So I'm making a roleplay type game and I want it to give cash every 5 seconds but it isn't working. This is a script in the ServerScriptService. Here is the code
local plr = game.Players.LocalPlayer while true do plr.leaderstats.Cash.value = plr.leaderstats.Cash.value + 5 wait(5) end
If you know what is wrong send me the new code. leaderstats is a model not folder. The error is 16:37:15.276 - ServerScriptService.Script:5: attempt to index nil with 'leaderstats' Thanks!
You're trying to access the LocalPlayer through a ServerScript, this will return nil
thus there is nothing to access from it, so what you should do is:
game.Players.PlayerAdded:connect(function(player) local leaderstats = player:WaitForChild('leaderstats') while wait(5) do leaderstats.Cash.Value = leaderstats.Cash.Value + 5 end end)
Hopefully, this helps :)
Also, it seems like you are still learning the basics of scripting, so I suggest researching about LocalScripts and Scripts :)