What is the best practice for storing and handling save data?

Basically what the title says
In a multiplayer setting, what would be the best practice for handling storing, editing, and reading save data? Should it all go through a module script? Should everything go through a singular saving script or should it be modularized? Is using _G a bad idea? How should data be stored locally (since constantly calling the datastore won’t go well)? How should conflicts be handled (if they occur)? When should UpdateAsync be used over SetAsync? How should backups (in case of corruption) be handled? When should you use multiple DataStores? (yes that’s a lot of questions)

I just want to know everything I need to know. Kindly do not recommend third-party modules (such as ProfileService). My goal is to learn best practices and learn how to handle it myself not just to quickly make a saving system. Tutorials are fine however.

1 Like

Just datastore all info on start and end
Works very well, and there are not that many usecases where another technique would be required
The less requests made to datastore API, the better

Would it be bad practice to also store data periodically (like every 5 minutes) just to be safe? I really don’t like the idea of risking data loss in case something goes wrong

No, that is definitely not an option
Datastore service allows 60 datastores + 10 per player

They removed the time limit on datastores though, so even if there was a server shutdown, you could link a bind-to-close to stall for time to get the rest of all your players’ data saved

What do you mean by “Datastore service allows 60 datastores + 10 per player”? I can’t think of any limit I’ve seen that looks like that

  1. Im using module script for saving because i think its much easier to interact with. I have a function Get which returns stats and can be easily changed.

  2. If save failed on player leaving, there is not much things you can do, if that happened, probably your periodic save works incorrectly. If periodic save falied im kicking the player from the game to prevent dataloss.

  3. I recommend using UpdateAsync for saving player stats because it works faster for cross-server replicating stats.

  4. Use different datastores for leaderboards, player stats, moderation logs and etc

If you check the newly released devforum by roblox on removing the datastore time limit, it mentions that limit

UpdateAsync, SetAsync, GetAsync and other datastore methods has limits. Read Data Stores | Documentation - Roblox Creator Hub for more info on that.

Well checking the limits I guess it depends how you store data
If you store everything within a json encoded table then you are really unlikely to hit the limit, however if you store everything under different scopes or datastores all together, you probably will hit it really quick