Player Experiencing Data Loss in my TD Game

One thing I’d like to let you know is to not use SetAsync() if the player already has existing data. To update a players data that already exists in the DataStore, use UpdateAsync(), for new players that join your game for the first time and don’t have any data use SetAsync(). Using SetAsync() for updating data is a very bad practice and is reason behind most data loss problems.

You can find more about that here. Stop using SetAsync() to save player data

I also recommend checking out public modules like:

ProfileService - [ Save your player data with ProfileService! (DataStore Module) ] (Recommended as it is more feature rich and includes “session locking” to prevent item dupes)

OR

DataStore2 - [ How to use DataStore2 - Data Store caching and data loss prevention ]

Both handle issues with data loss and have many great features for saving/loading data, so you’d never have to worry about players losing their data again.

Now, as for your code the issue can lie in Roblox DataStore simply failing or you have updated player data with something blank. What we can do is to find the actual issue and we can do that by logging data saves.

I can see that your pcall function in Data Saving, at the bottom of the script, where youu :SetAsync() the users data, doesn’t actually handle the “fail” circumstance (What if success2 isn’t true? That would mean saving has failed due to an error! But considering you don’t handle that case anywhere in your script, if saving fails the script just doesn’t do anything about it and proceeds with the rest of the script, which is deleting the playerFolder after a second).

You should handle success2 if it’s not true, as it would mean the script failed to save to DataStore. You can add a logger to it that would let you know if user data has failed to save so you can determine the issue closer and handle it.

Also, check the data of players who are reporting data losses. If the data structure (datatable) is present but the data for each entry is nil, then it must mean your script isn’t properly saving the data. That can also help you with finding out the cause of data issues.

Hope this is of help, pleasure to assist you further.

2 Likes