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

Why does my saving system not work anymore?

Asked by
sydre 229 Moderation Voter
6 years ago

For about 8 months ago, I found a script that would save data to DataService so that the Money players of my game had would save. But when i ran the game about 4 months ago, it didn't work anymore. I've searched after working scripts everywhere but every script i can find was made Before 2016 and doesn't work anymore. Is there anyone that knows what's wrong with the script or Another saving script?

script:

local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("MoneySaveSystem")

game.Players.PlayerAdded:connect(function(plr)

local folder = Instance.new("Folder", plr) folder.Name = "leaderstats"

local money = Instance.new("IntValue", folder) money.Name = "Money"

money.Value = ds1:GetAsync(plr.UserId) or 0 ds1:SetAsync(plr.UserId, money.Value)

money.Changed:connect(function() ds1:SetAsync(plr.UserId, money.Value) end)

end)

1
put in codebox. yHasteeD 1819 — 6y
0
also, don't use the parent parameter of instance.new, it hinders performance theking48989987 2147 — 6y
0
Any errors in the console? Kullaske 111 — 6y

1 answer

Log in to vote
0
Answered by
Kullaske 111
6 years ago
Edited 6 years ago

This should work. If it doesn't please comment the error.

local datastore = game:GetService("DataStoreService") 
local ds1 = datastore:GetDataStore("MoneySaveSystem")

game.Players.PlayerAdded:connect(function(plr)

local folder = Instance.new("Folder") 
folder.Parent = plr -- You should never use the second argument of instance. It is VERY slow
folder.Name = "leaderstats"

local money = Instance.new("IntValue")
money.Parent = folder 
money.Name = "Money"

local MoneyAmount = ds1:GetAsync(plr.UserId))
MoneyAmount == nil then -- I believe the issue you had was that there was no value set in the datastore.
    money.Value = 0
else
    money.Value = MoneyAmount
end


money.Changed:connect(function() 
    ds1:SetAsync(plr.UserId, money.Value) 
end)

end)

I also fixed up some of the syntax. You shouldn't use the second argument of instance. In this Devforum post you can see that it's very slow compared to just sending the parent in another line.

0
I tried the script and it works but i also found another working script after i posted the question that broke without me doing anything after about 2 hours. I let you know if the script breaks or if it still works after a while. Thanks for the respons and have a good day! sydre 229 — 6y
0
Could you mark my post as the solution? Kullaske 111 — 6y
0
ok so i have had the script for 2 hours now and it have stopped working. I added and changed the name of a couple things in the script but it worked well when i tested in. From it working to now i have only done some things in the workspace, added some Gui's and made scripts that would change the value of the money but i havn't toughed the saving script since it worked last time. sydre 229 — 6y
0
Do you kown what causes this and how to fix it? sydre 229 — 6y
0
It's the saving part that doesn't work btw, When i go into the game it loads up the money i had last time it worked but it doesn't save the money i earn. sydre 229 — 6y
Ad

Answer this question