Players' data seems to randomly revert to an older version

I have a data saving system in my game that uses SetAsync() to save a table and GetAsync() to retrieve the table. I am aware that people say that SetAsync() is terrible to use, but I don’t understand why it doesn’t seem to work properly in my game or if it’s actually the cause of my problem.

My game saves data every time the player gets coins by playing the game (which can only happen once every 12 minutes), every time they purchase a coin Dev Product, and when they buy a new item with their coins. I don’t get any warnings in the Dev Console about calling a key too frequently or on data being unable to save (which my code is set up to warn if saving data fails). I also have a system in place that renders everything a player earns if their data failed to load when they joined the game that prevents their real data from being overwritten. I also have data save using PlayerRemoving and GameBindToClose.

Also, there is only one data saving function that gets called to save the data, so it’s not an inconsistency with me updating some copy-pasted code and forgetting to update others. And there’s no Place teleporting in my game.

I and other players have witnessed data loss and it seems to never revert back to what players just starting out have, it just seems to revert back to what they had in the past, like an item they recently bought is suddenly not bought anymore and their coins revert back to what they were before they purchased a Dev Product to get coins. Data loss only appears when they join the game again. Data does not randomly disappear while playing.

I also don’t use ModuleScripts to hold player’s data. I use Values located in the Player. I’m not sure if that would be an issue or not unless my data is saving too fast before the server can actually update the Value. I always tell it to update the Values first and then save.

So is this a problem with GetAsync() or SetAsync() and how?

Edit: It turns out I get very “few too many requests to save to this key”, So I don’t think any save requests are being dropped…

Does the game automatically save the data of players right before they disconnect?

1 Like

Yes, I forgot the mention that. I’ll add that to the original post.

I don’t know much about DataStore in general but:

  1. There’s probably a good reason why so many people don’t want to use SetAsync() like you said. It’s gonna be hard for you to get answers if you’re against the majority.
  2. Having it autosave periodically seems redundant; it should really only save when the player is about to leave or when the server is about to shut down.
  3. Perhaps look over everything in your code, there might be some oversight.
  4. Have you tried properly debugging it, such as by comparing the data stored in DataStore with the currently present data? You could try printing out literally everything it does step by step, that should help pinpoint the problem.
  1. There’s probably a good reason why so many people don’t want to use SetAsync() like you said. It’s gonna be hard for you to get answers if you’re against the majority.

Yes, you are probably right about that. I just don’t know why it would cause me issues in my case.

  1. Having it autosave periodically seems redundant; it should really only save when the player is about to leave or when the server is about to shut down.

Even games like Royale High save periodically and it’s considered good practice in case the Roblox DataStore servers start having issues while a player is playing, so they don’t lose everything, but will only lose what progress they made after the DataStores became inaccessible. The only reason I even save periodically is because I was told on several different occasions that it’s a good idea.

  1. Perhaps look over everything in your code, there might be some oversight.

I already have but I’ll certainly be doing it again.

  1. Have you tried properly debugging it, such as by comparing the data stored in DataStore with the currently present data? You could try printing out literally everything it does step by step, that should help pinpoint the problem.

Mostly. The only thing I can think to do that I have not done is print() out the entire table of data every time one is made for the DataStore. I’ll be doing that now and testing with it, so it’ll take me a while.

Okay, so I have been printing out the Success value, the ErrorMessages, and the entire table that I’m saving. I have gotten no error messages and it keeps returning true for success, meaning that it is saving and retrieving data as it should be, and all of the data in the table I tell the DataStore to save is correct. It’s when the data gets retrieved. It will frequently pull up all the correct data when I hit Play again, but once in a blue moon it will load old data from several sessions ago and it seems random at that. I can’t find any consistency as to when it does it as the DataStore saved and loaded data correctly several times before deciding to revert to a really old version of my data.

Despite all of this, I do still appreciate that you tried to help me.

Reviving this old thread since it’s the only similar issue I can find on the forums.

I’m having this issue with a very small percentage of players in my game Infinite Item Simulator Infinite Item Simulator - Roblox

These players will make progress, log out, and when they log back in they have reverted to some old data.

To further test this, I used Superbiz.gg Data Store Editor to view the data store as it is being updated. I have the player login to the game, make some progress, and then logout. Viewing the data store in the Data Store Editor I can see that their data has been updated successfully into the data store when logged out. However, as soon as they log back in their data has reverted to an older version of the data. This can be repeated as many as times as we like and the result is the same.

One time when the player logged back in they had their correct saved data. However, when they logged out and back in their data once again reverted to the older version of the data.

To ensure it wasn’t an issue with our PlayerStatManager script giving them data from a local copy of the data, I had them make progress on one server, log out, verify that it saved into the data store using the Data Store Editor, and then had them log in to a private server. When they logged into the private server their data reverted back to an older version.

I haven’t been keeping up-to-date on how DataStores work but here’s an old post I followed and fixed my data issue with. All I know is that I swapped to using :UpdateAsync() and threw in some extra code and it stopped happening.

Actually… here’s the post about using :UpdateAsync() and how to use it to your advantage:

I’m still not a master at DataStores, and I feel that way because of the one and very inexplicable issue you are having. It’s just that this is how I fixed that issue a long time ago. And STILL the fix makes no sense to me. Like if :GetAsync() gives old data sometimes, why doesn’t :UpdateAsync() have the same issue? I find it quite frustrating that I don’t know why :GetAsync() doesn’t seem to work properly sometimes.