I found a data save from the Roblox wiki and it works well except if you go in game with some ingame money and spend it to 0, then if you leave and rejoin the game, you will have your original amount of money. It doesn't seem to save 0s.
01 | scoreKey = "PlayerScore" |
02 |
03 | game.Players.PlayerAdded:connect( function (player) |
04 | if player:WaitForDataReady() then |
05 | -- create leaderboard |
06 | local ls = Instance.new( "IntValue" ) |
07 | ls.Name = "leaderstats" |
08 | ls.Parent = player |
09 |
10 | --create the score stat |
11 | local score = Instance.new( "IntValue" ) |
12 | score.Name = "Money" |
13 | score.Parent = ls |
14 | score.Value = player:LoadNumber(scoreKey) |
15 | end |
Please help, I assume is is only a matter of a few lines of code.
I've had this problem in the past, all you will need to do is make the 0 into a -1, you're correct just a few lines of code.
01 | scoreKey = "PlayerScore" |
02 |
03 | game.Players.PlayerAdded:connect( function (player) |
04 | if player:WaitForDataReady() then |
05 | -- create leaderboard |
06 | local ls = Instance.new( "IntValue" ) |
07 | ls.Name = "leaderstats" |
08 | ls.Parent = player |
09 |
10 | --create the score stat |
11 | local score = Instance.new( "IntValue" ) |
12 | score.Name = "Money" |
13 | score.Parent = ls |
14 | if player:LoadNumber(scoreKey) > = - 1 then --If score is less than 0 then |
15 | score.Value = 0 --Score will equal 0 |
Hope this helps.