How should i handle DataStores failure?

Greetings again devforum community, i’m getting started to write my first datastore code, and there’s something i need help with, how should i handle DataStores failures?

For example, if the data fails to save, should i try to save it again and again until it finally succeds?

Or what should i do if the game fails to load the data? Should i warn the user about it and ask if he wants to retry?

If the player leaves the game, dont really think the player could do that :sweat:

But, what you could do is just not save the data (if you’re using setasync) since that can override it with nil aka 0 and that is basically just data loss. You should also try using UpdateAsync() if you arent already since it uses the previous data and checks with it and if the data fails to save, you can always just use the data from before as a replacement.

1 Like

So, if the player leaves the game and the data fails to save, i should just give up? What if the player was really far ahead?

Why shouldn’t you just save the data when the stats changed/increment? And if that fails, then you could do the method you said where you try to save it again and again. Though, I recommend using UpdateAsync() if you aren’t using it yet since it also takes in account for the last data.

(Also, you should only try to not save if the data fails if you’re using SetAsync() since it sets the value instead of taking in account for the last values and if that fails, it makes it 0 which is much worse then losing some of your data)

Edit: Remember to take in account of limits since that as well can mess up your data: Documentation - Roblox Creator Hub

What’s the difference between UpdateAsync() and SetAsync()? I’ve already read the articule but i still can’t figure it out.

UpdateAsync() takes in account of your last data for example, lets say you get 50 noobs every time you collect a golden noob. UpdateAsync() takes your last value and adds onto it so like: 50 noobs (previous data) + 50 = 100(newdata). SetAsync() works differently, It sets the value instead of taking in account of the previous for example: 50 noobs, set to 100. It doesn’t take in account of the last data so if it fails to set it while leaving the game for example, it could set it to 0. Which pretty much means you lost all your data.

@ForeverHD provides an example and reason why you should use UpdateAsync(): Stop using SetAsync() to save player data

Edit: If you want backups of datastores to make sure your players dont lose all their data. You could use DataStore2: How to use DataStore2 - Data Store caching and data loss prevention

But if you’re just planning to use a normal datastore, use UpdateAsync()

Thanks, that cleared it up, so, use UpdateAsync() to Update player data.

However, what about datastore throttle? how do i handle that?

The Roblox Wiki Talks about how you should handle it: Documentation - Roblox Creator Hub

If you’re using UpdateAsync(), this equation: 30 + numPlayers × 5 Should give you how many requests should be done in a minute.

1 Like

Thanks, all of my questions were solved!

1 Like