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
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.
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)
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.