Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my saving system not work anymore?

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)

3 comments

1

put in codebox.

0

also, don't use the parent parameter of instance.new, it hinders performance

0

Any errors in the console?

1 answer

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.

5 comments

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!

0

Could you mark my post as the solution?

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.

0

Do you kown what causes this and how to fix it?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.