How do I solve these possible datastore problems?

There are a few datastore problems I’ve heard get talked about here, but I’ve never actually found a solution to any of these.
1. What do I do if a player leaves a server and joins another quick enough that the first server doesn’t save in time and the second server loads older data?

2. Should I overwrite data if when using UpdateAsync the older data is infact more recent data? What if a player made a purchase on older data, do I still overwrite that data even though they purchased, for example, currency on that old data save?

3. Am I responsible if a player purchases currency and through an error their data is lost to refund them? I’m assuming so, and if so, how do I verify that they actually lost data with a purchase?

4. How do I accurately test datastore errors to prevent an unknown bug in my script causing major data loss in the future?

5. What is the best way of handling data loss if a player leaves a server and I am unable to successfully update their data? For example, if Roblox datastores are down? Do I just accept I can’t do anything and let their data go unsaved? What if they made a purchase, and I was also unable to record their purchase in a datastore?

6. Do I include error handling for every error separately, listed on the developer hub? Would that be unnecessary to do?

7. Am I overthinking or over worrying about these problems? Is making a secure save system with minimal data loss as simple as using pcalls, certain good practices and leaving it at that?

Most examples I see on datastores are relatively simple, with using pcalls and retrying a few times. Is this all you need to do? I’m assuming most games on the front page use techniques or better ways of saving data with datastores. I feel very lost working on datastores because I hear about all these potential problems with datastores, yet all the examples I come across seem to not mention anything about these problems. I’m attempting to make a near perfect system so I wont ever have to deal with data loss or refunding purchases, but I don’t know if I’m worrying too much about this.

Also whenever I begin working with datastores I usually decide it’s too stressful and end up using Datastore2, I’m hoping to avoid using Datastore2 in order to help myself get better at scripting and understanding exactly how datastores work. Thanks!

1 Like

I’ll try to answer these questions as best as I can…

  1. Nothing you really can do. That’s on the player for having too amazing of internet speeds. Generally Datastores update quickly. My only solution to that is to check again after 5-10 seconds to see if the data has been updated.

  2. Not really sure what the question is here… Yes, you should use UpdateAsync on older values since it’s more reliable. Include a separate receipt history for purchases so you never have to override them.

  3. Depends. Sometimes data retrieval issues happen. If you’ve followed everything Roblox tells you to do, it isn’t your fault. Actually, you are able to find transaction logs on your account for player purchases. This can be used as evidence for a player’s purchase.

  4. Nothing I can really tell you here. You can’t predict the future but you can test what you know for common errors. Even big games have things pop up that never showed up in the bug testing trials. It’s just a thing of life-nothing’s perfect.

  5. Unfortunately, again, there’s nothing you can do to combat this. The most we can hope for is that game:BindToClose saves us with it’s 30 second marker so you can keep retrying. Data loss is data loss and any player will understand this.

  6. Eh, I mean that’s up to you. It’s just a matter of preference really. Should you compensate for every error you can? Absolutely, it’s good practice. However, not everyone does all of this because not every error is common. I would fix the common ones and then cover the later ones as they come up.

  7. Short answer, yes. Sometimes things are out of your control.

2 Likes

Thanks for the answers! I just wanted to follow up on a few of your answers with some questions, if you don’t mind answering:

I phrased this question badly, my bad. Essentially, let’s say I have a version attached to each player’s data, and every time I save their data I increment their data’s version to show it’s more recent. If, by using update async, the old data has a version that is later/more than their current data’s version that is being saved, would it be best for me to instantly overwrite their current data, as their “old data” is actually a later version? And in terms of purchases, if a purchase for currency was made on their data which was a lesser version, do I overwrite anyway?
I think the answer is probably up to me to program transferring purchases, which will be hard but I’ll attempt it.

This makes sense, thanks. How about with common errors, such as roblox datastores simply going down? How do I accurately replicate an error like this happening in studio to see if my system handles it properly and doesn’t overwrite data or anything? Should I just change my code temporarily to force an error?

Other than that, thanks for your in-depth response! I’ll try to avoid worrying about rare situations and situations out of my control too much, and stick with normal good practices.

For 1, I am not sure how this would ever happen but yes, always go with the more recent version as that is the most accurate. I assume this ties in with the first question.

For 2, you should never have to worry about Roblox’s Datastores going down. It isn’t a common error nor should it be treated as such. That is on Roblox’s end and is their issue. What you should worry about is how you catch and handle issues like the Datastore Service rejecting a request or failing to grab information. Those are common issues.

1 Like