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

Datastore Money Value is not saving correctly, any help?

Asked by 4 years ago

I have this modified script mostly inspired by Youtube and it doesn't fully work. The Kills value saves perfectly, unlike the Money. What happens is that after a few hours to days, most of the total Money earned will reset or decrease about 80-90%. Being a nearly essential part of the game, I believe resetting the value will just erase everybody's total progress and possibly encounter the problem again. This is a trend in all players that exceed 1000 in cash. I currently have more than 2000 kills, and I should have three times the amount in cash, however my data just erased several times and I currently have about 450 Money.

As I got this tutorial on how to make it from YT, I am not sure how to troubleshoot or fix this.

Note: Money is gained from killing players and NPCs, and is used on things to buy. Kills are just collected.

01local datastore = game:GetService("DataStoreService")
02local ds1 = datastore:GetDataStore("MoneySaveSystem")
03local ds2 = datastore:GetDataStore("KillsSaveSystem")
04 
05game.Players.PlayerAdded:Connect(function(plr)
06    local folder = Instance.new("Folder", plr)
07    folder.Name = "leaderstats"
08    local money = Instance.new("IntValue", folder)
09    money.Name = "Money"
10    local kills = Instance.new("IntValue", folder)
11    kills.Name = "Kills"
12 
13    money.Value = ds1:GetAsync(plr.UserId) or 0
14    ds1:SetAsync(plr.UserId, money.Value)
15 
View all 39 lines...

1 answer

Log in to vote
0
Answered by 4 years ago

Quite simple fix, you just mixed up the keys.

01local datastore = game:GetService("DataStoreService")
02local ds1 = datastore:GetDataStore("MoneySaveSystem")
03local ds2 = datastore:GetDataStore("KillsSaveSystem")
04 
05game.Players.PlayerAdded:Connect(function(plr)
06    local folder = Instance.new("Folder", plr)
07    folder.Name = "leaderstats"
08    local money = Instance.new("IntValue", folder)
09    money.Name = "Money"
10    local kills = Instance.new("IntValue", folder)
11    kills.Name = "Kills"
12 
13    money.Value = ds1:GetAsync(plr.UserId) or 0
14    ds1:SetAsync(plr.UserId, money.Value)
15 
View all 39 lines...

For the player removing, you had it as a different key than the player added.

0
If this still causes you problems then I don't know how to fix them, as I've never seen a datastore script formatted like this. ParticularlyPenguin 71 — 4y
0
Thank you, I was going into this semi-blind and hope it is simply my mistake. I will let you know if this works. Bgonzalezseeya11 27 — 4y
0
The fix did not solve the problem, but it did reduce how much money as lost. Thanks for your help. Bgonzalezseeya11 27 — 4y
Ad

Answer this question