Why is my game experiencing dataloss?

This isn’t the solution of this bug but it will deffo help if people try to join and leave supe quickly

I will try this out! So far I made it so if data ~= nil or BS:UserHasBadge(UserId, the has played badge id )

1 Like

Hope that fixes the problem, glad I could be helpful! :slight_smile:

I believe that @imNiceBox made the first correct suggestion on this thread. While it isn’t totally clear from your code since you haven’t posted all of it, a common situation for data loss is as follows:

  1. Player joins the server
  2. Server attempts to get data using GetAsync, but it errors
  3. Server loads default values for the player
  4. Server saves over existing data using the default values

The only situation in which you should be allowing a player to proceed with default value is when GetAsync does not error AND returns a nil value. When GetAsync errors, you should hold the player in a “loading” state that does not allow their data to save until you have confirmed that you have loaded their data successfully.

Most of the time DataStore works perfectly as intended without any errors, but occasionally Roblox has service outages which cause calls like GetAsync and SetAsync to fail, causing an error.

The above scenario describes how a player might have their entire data file overridden by a GetAsync fail, but a player can also lose their data for a particular session if SetAsync fails during your PlayerRemoving code. For this reason it is good practice to periodically auto-save a players data while they are in your game, so that in the event that you are unable to save when they leave you minimize the amount of lost time.

3 Likes