Tips to avoid data loss

Hello,

I want to step up my game with datastores and I was wondering if any of you could leave me some helpful tips/points that help prevent any dataloss or any other issues.

A question I have on the side is:
I tend to wrap my SetAsync/UpdateAsync in pcalls but my concern is what I should do when there isn’t a success. What I had in mind is that when there is a failure I have a repeat loop until it succeeds i.e saves properly but this can throttle the datastore right?

3 Likes

Here’s what I do in my games:

  1. Save periodically on a timer
  2. Save on any Robux purchase
  3. Save on exit
  4. For each save, wrap it in a pcall to ensure success
  5. If not successful, try again a set number of times with an exponentially increasing delay (first retry is after 2 seconds, second retry after 4 seconds, third after 8 seconds, fourth after 16 seconds, etc)
  6. Display a warning message to the user to let them know any progress they make may not be saved if a DataStore request fails. Remove this message if a save is successful.
  7. If on game join a player’s data fails to load, give them new data with a marker that makes it not save and display a warning message to the user telling them they may need to rejoin.
18 Likes

Makes sense. What I am going to do is I will save periodically, on purchases and on PlayerRemoved & bindtoclose.

So if PlayerRemoved/BindToClose fails, at least there will be that periodic save as a backup and he won’t lose anything he purchased because of that save on purchase.

2 Likes