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.