I made a poorly done post a few days back on this subject, but recently some changes were modified to the datastore by @SteadyOn and I, but there are still reports of players losing data.
Here’s the a pastebin of our saving/loading data. It loads when the player joins, and saves when they leave. https://pastebin.com/MSuMTHud
I’ve looked over my system multiple times, but I still can’t get my head around why it isn’t working.
I’ve decided to spend a good hour on my game, playing, rejoining, etc. But my data saves and loads just fine every time, yet me and @TheHyb still are getting complaints about data loss.
I even looked in the server log for errors, but there are always NONE.
The player leaving is not always the most reliable method. Servers crash, other edge cases happen. You should consider saving data at a regular interval. A common one is to do it every minute, as it should help to keep you from hitting your limits.
You should also be auto-saving every so often (e.g. every 60 seconds–nothing super frequent), and also make sure you save when the game closes using BindToClose. This is crucial, because it allows your game to prevent itself from actually closing down until all the tasks are done within the BindToClose functions. If you only rely on PlayerLeaving, it might not be able to save data for the last player to leave.
Store player data in ReplicatedStorage or ServerStorage. Never store it in the actual player object. Always use BindToClose to save for the last player like Crazyman32 said. Save in a few minute intervals in case of a crash. A combination of all of these methods haven’t failed me yet when I apply them.