I'm developing my own game but datastores seem to be an issue. I originally had a game with a few players, and my datastores throttled a lot even though I only saved once every 60 seconds and when a player leaves. The problem is I have dev products that give e.g cash, and their purchase is technically worth nothing if their data is lost. Is there any fool-proof methods of recovering data or preventing data loss, including if Roblox has problems with datastores failing globally?
The way's I normally handle it is I make a function to save the values and run it whenever a player leaves If the server is said to shut down, And lastly every 60 seconds. Here are some examples of what I mean.
local function saveValues(player) -- CODE GOES HERE end game:BindToClose(function() if not #game.Players:GetPlayers() == 1 then -- Don't save twice if its only 1 person leaving. for i, player in pairs(game.Players:GetPlayers()) do saveValues(player) -- Call save function end end end) game.Players.PlayerRemoving:Connect(function(player) saveValues(player) end) while wait(60) do for i, player in pairs(game.Players:GetPlayers()) do saveValues(player) end end
I would also like to mention that It can be worth running the function to save values if you get an important stat, for example, you get a legendary item in the game. Or if you just rebirthed.