Datastore2 fetching old backups after successful save

I’ve had an issue with Datastore2 where a player can leave the game, their data will supposedly successfully save, and they rejoin to see their save from the beginning of their last session. I’ve only seen this first-hand one time and I cant seem to recreate it. My biggest concern with this is i’ve never seen anyone else having data loss issues with datastore2. I’ve had player reports of losses since I was using it in a game with 10-30 players, and I also get reports in a game with 30,000+ players. I’m hoping theres just a little issue with my implementation, but I have always tried my best to follow the docs

This is my .Combine, called once, i saw somewhere, someone calling it on every .PlayerAdded, could there be any downsides to doing that?

if not RunService:IsStudio() then
	Datastore2.Combine("Test21", "Money", "ToCollect", "Purchased", "Cars", "ExtraClaimed")
else
	Datastore2.Combine("Test23", "Money", "ToCollect", "Purchased", "Cars", "ExtraClaimed")
end

the first call to a new player’s data:

    local plrmoney = Datastore2("Money", player)

	local plrStats = Instance.new("NumberValue",game.ServerStorage.PlayerMoney)
	plrStats.Name = player.Name
	plrStats.Value = plrmoney:Get(100)

I’m using the latest release from github
I’m considering switching this game to another module, but a lot of the game’s core functions are heavily reliant on datastore2’s functions and events. I’ve tried contacting the author.

It’s mostly reliable but it hurts to receive reports from players who’ve spent time and robux in our game, left the server without being disconnected or anything, and came back to see that no recent progress has been recalled.

I dont see an issue calling combine.

How I usually set up though is

local plrmoney = Datastore2("Money", player)

plrmoney:Get(100)

plrStats.Value = plrmoney

I don’t think there is any difference though so it ultimately looks fine.

can you show all code snippet for when you set then to different values? Can you also describe what type of game you refer to? I recall having a similar issue where I implemented ds2 with a game where mass teleporting was involved and there were issues with potential dataloss due to how ds2 saves (or atleast I believe it to be so) someone may buy an item and later teleport and a mass queue would result from teleporting with other players and it just could not save in time for the player to then join the teleported server with the same inventory etc. as when he joined.

I fixed this particular issue by ensuring to manually save ds2 when player bought something and changed values

Tycoon, only one game in the experience. I didnt know you could still manually save with ds2, i thought they deprecated that or something. Should i make an autosave loop? Also, are you saying theres nothing wrong with calling combine on every PlayerAdded? can’t tell from the way you said it

My code is nothing special, theres definitely way too many of these to post here lol.

plr_money:Increment(-price)
cars_store:Set(plr_cars)

Sorry, I meant calling combine once in completely fine and is exactly what I do in terms of calling it–once.

I can’t tell that there’s anything wrong, personally I don’t use increment, I use the set method, either should be entirely fine. The way DS2 saves is utilizing a local cache and when the player leaves it sends a save request to roblox. That is how ds2 natively works.

The only other path to solving this issue is to experiment try it once:

Open up a test with maybe 4 players (ability in studio) and ready yourself with 3 of the 5 browsers (the 5th browser is the server, and have the game loaded up where the players are actively changing their datastore values (if possible)

quit out of the three servers in quick unison and view any output within the server’s output (try to minimize any other prints you may have so you may be able to locate more important datastore info) Also make sure you have saveinstudio bool set to true.

There isn’t a reason to manually save in your case, you shouldn’t need to resort to it–however if the above experiment brings no clues I suppose you would have to implement an autosave feature which I can help with, it will be complex but It will work

My idea is that upon successfully setting data up in playeradded, table.insert the player into a table named AutoSave

know that there is a queue time and we don’t constantly want make queues onto roblox datastore so in a while loop, enter a for loop with the AutoSave table and access player, and utilize the saveall instead of save async due to multiple ds

so it should be like this: DataStore2.SaveAll(player) --this is according to api documentation, I only used saveasync before so be sure to experiment if you try this out

sample code:

while true do

for index, player in pairs (AutoSave) do

if game.Players:FindFirstChild(player) then  -- or player.Name please experiment here
--player successfully validated, go ahead and saveall
DataStore2.SaveAll(player)
wait(5) -- wait time for saving is necessary to avoid large queues
else
table.remove(AutoSave, index)
end

end

wait(30) -- wait(30) for new data

end

I don’t recommend this though nor would DS2 creator, but im at a significant loss at what could be causing it, especially if the experiment turns out no clues.

1 Like

Nothing came of the experiment rip. Working on autosave, thanks for the help. I hoped there would be some obvious oversight on my end, ive been looking into the issue for months. ill use profileservice on everything in the future for sure