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)
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.