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.