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

How can I fix my money data save?

Asked by 10 years ago

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.

01scoreKey = "PlayerScore"
02 
03game.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
View all 22 lines...

Please help, I assume is is only a matter of a few lines of code.

0
M39a9am3R - When I put it in Roblox, it says it is broken and the last end is underlined. Champion121212 22 — 10y

2 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

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.

01scoreKey = "PlayerScore"
02 
03game.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
View all 29 lines...

Hope this helps.

Ad
Log in to vote
0
Answered by 10 years ago

Thank you so much!

Answer this question