Which is the best way to make sure data is saved?

I have two ideas of how to make sure data is saved, though one of them doesn’t mean your data will be 100% saved.

Idea 1)
When the player leaves, their data tries to save and is wrapped in a pcall. If it errors it’ll add the users data to a “save” queue that will go through the contents of the table, 10 seconds at a time (because i think that’s how much you have to leave between saving data) and attempt to save the players data until it does (waiting 10 seconds after every fail). Once it finally saves it’ll move onto the next person.

Idea 2)
When the player leaves, their data tries to save and is wrapped in a pcall. If it errors then it will attempt to save the data 3 times, after the third attempt if the data still hasn’t saved then it’ll just give up.

My original idea was #1; but I asked in a discord server I’m in if it’s the best way, and they told me #2 was the best way to go.

I also plan to save when important player data changes such as they buy an item, unlock a power, etc.

I haven’t really done much DataStore / Saving Data stuff, so I’m sorry if it’s an obvious question.


There’s really no reason IMO to make data saving asynchronous, so in that area, #2 is the way to go.

It’d be best if you did saving every time interval – e.g. an autosave every minute – or when a player leaves (ideally both at once). Saving every time a player buys something will cause errors if they buy more than 10 things in a minute.


As EmeraldSlash said

you should ONLY Save Data in these 4 scenario

  1. When Player leaves

  2. Auto Save Every X Seconds or Minutes

You can read more about the Limits on the Wiki and calculate how often you want to Save Data

  1. When Player clicks “Save Data Button” if there is one in the game, and remember to add a cooldown, you don’t want Players to spam it.

My game Saves every 5 Minutes & When the player leaves. I might add a Save button.



You should also save when the game closes using BindToClose.

   -- Save data

There’s a pretty good wiki page on saving data player data.