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

What are the best ways to prevent data loss?

Asked by
trecept 367 Moderation Voter
5 years ago

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?

0
I've seen that post before actually and it looks good but I'm a bit confused. Currently my game is almost complete, and I don't know if the post is saying I need to create the values within the module. Is it possible for me to use datastore2 to just save existing values without creating them? trecept 367 — 5y
0
I haven't touched datastore2 yet, I don't know. But you can experiment with it to see. User#19524 175 — 5y
0
I will check it out later then, thanks! I'd still be interested in seeing if I could script a datastore script myself that is as close to efficiency as DataStore2 trecept 367 — 5y
View all comments (2 more)
0
I'm intrested, im also doing Datastores for the first time. How many players did your original game have that you said was getting throttled a lot? ShinyGriffin 129 — 5y
0
@ShinyGriffin I was at around 30 to 40 concurrent players at once on my game, and servers were 30 players each. trecept 367 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
Line 6 will not work as you expect for it to. `not #game.Players:GetPlayers()` will be false, since the `not` is applied to the number, which is then saying `if false == 1 then`, which will never execute. `if not (#game.Players:GetPlayers() == 1) then` is what you're looking for, but to make it simple just do `if #game.Players:GetPlayers() > 1 then`. User#24403 69 — 5y
0
This is not how you want to special case the last player anyways. Datastore writes are asynchronous, so you want to have a dictionary of all the players who are currently in the process of saving, and on BindToClose() initiate save for anyone not already saving, and don't return from BindToClose until the dictionary is empty. EmilyBendsSpace 1025 — 5y
0
It can still fail if not everyone saves in the 30 seconds BindToClose buys you, but you can't help that, there is no way to keep the server alive any longer. This is why you should definitely save immediately for important transactions or events, as this answer recommends. EmilyBendsSpace 1025 — 5y
0
I'm still curious how I would get around outages that apparently happen often where I wont be able to save or load data. trecept 367 — 5y
Ad

Answer this question