So here is my basic data store saving script:
local data = game:GetService("DataStoreService"):GetDataStore("SavingMoney")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats
local key = "Player-"..player.UserId
--Loading The Data
local success, errormessage = pcall(function()
newdata = data:GetAsync(key)
end)
if success then
Money.Value = newdata
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "Player-"..player.UserId
local newdata = player.leaderstats.Money.Value
local success, errormessage = pcall(function()
data:SetAsync(key,newdata)
end)
end)
This works, I tested it by stepping on a brick that gave me 10 bucks, left and it saved. However, when I actually do the function and get the money (through a remoteevent FireAllClients()) it gives me the money but doesn't save? Don't know what to do to avoid this

1 comment
If you really want to save your values, you have to change it on server side. Alt., use BindToClose to prevent data loss on shutdown.