Datastores don't work properly on rare occasions

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.

Any idea on what could be wrong?

2 Likes

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.

3 Likes

I’m talking about people who already have had data in the past and have played multiple times are losing their data.

Talking about people who already had some data, not new people’s data not saving.

1 Like

I don’t think the code you’ve provided is enough to fully diagnose the issue. There are a few obvious problems, but I need to see a few things:

  • PlayerRemoving code
  • GetData function

The largest issue I see right now is the fact that you are only waiting 1 second between failed attempts when saving data. A data store limitation is the fact that write requests to the same key have a 6 second cooldown.

1 Like

If this helps here you go
https://pastebin.com/dR0s135L

GetData() is just a function to get the player’s folder of data that will be used in the datastore

https://gyazo.com/19d37ce2f489d7d7eee54aebf372501b

1 Like

Really stumped on this

1 Like

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.

2 Likes

Just added that, I don’t think it’ll solve all my problems, but we’ll see.

2 Likes

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.

1 Like

Players are still reporting data loss. I honestly give up at this point.

1 Like

I’ve decided to switch to storing data in ReplicatedStorage, hopefully this will work.

1 Like