Values such as money should be changed on the server. This is because if it's changed on the client, it will not be saved / viewed by the server. Meaning only the client can see what it's been changed to. This means you can **not ** use local scripts.
Next point is that scripts in ServerStorage do not work. But I believe you were meant to put serverscriptservice.
Finally, game:GetService("Players").LocalPlayer does not work on the server. This may be the problem if those over two points are allready covered.
This is because the client so local scripts have a local player as they only run on that one player, when server scripts dont as they run on the server.
I am guessing you are wanting this to run for every player, there is a way to do this.
game.Players.PlayerAdded:Connect(function(Player)
local randomcash = math.random(0.01, 10.00)
local Cash = Player.leaderstats:WaitForChild("Cash")
while true do
Cash.Value = Cash.Value + randomcash
wait(10)
end
end)
And that should be your new server script, in serverscriptservice.
I am going to now explain the two lines of code I added:
game.Players.PlayerAdded:Connect(function(Player) will simply run the code up untill end) when any player joins the game. It will return Player as the player that joined replacing the game:GetService("Players").LocalPlayer line, making the code run on the server.
1 comment
You should get rid of the print, I just put it there so I could make sure the random cash was adding up when I didn't connect it to a leaderboard