What should i do when there's a saving error in DataStore?

I’m kinda worried of people in my upcoming game who might buy something (Such as a currency), and when they leave, an error will happen, and they will lose what they bought, i don’t know how to handle these kind of issues, i would like to know a way to prevent this, not like having a solution that prevents anything like that (But still appreciated), i just want to handle this stuff without losing the data completely, without having any option to use. Thanks for reading.

Personally I would have it instantly save to my data store as soon as the purchase is made. I highly don’t recommend saving only when a player leaves, you should be regularly updating your data-store (automatic saves) and saving when they leave or make purchases.

1 Like

Ahh, yes, this is a common issue.
Since datastore erroring is common, you can use these three solutions (I use all three in my games)

  1. Encase any savings in a pcall(). If you don’t know how to do this, do local success, errormessage = call(function() --your function here
  2. Repeat the call until success is not equal to nil, or you have repeated more than three times. Wait 2-3 seconds between each repeat
  3. Use autosave every 1-3 minutes, or every time somebodybuys something

I am assuming you have a basic scripting knowledge (about datastores). Let me know if otherwise and I will give you a script.

1 Like

Nice, but i have a question, it could reach the limits of Getting/Setting/Etc-ing with DataStore?


@Scepter_ofDarkness Thanks for your help, since you have a better knowledge about DataStore, i want to ask you one more thing, it is possible to know when a saving issue occurred? And notify the player about that in a different moment? (What i mean is to know when there was an error, and know when that player joins again, and get any error that occurred, not necessary to give me a whole script or explaination, maybe a yes or no)

Thanks for reading and helping!

I use Datastore 2 which has a very effective way of saving data

Not really, I use my own custom fire base admin SDK to backup data. 100* more efficient. I can also change data on the spot from fire base real time storage. I would suggest looking using your own system instead of data store 2

Yes.
Here is the code which will repeat the call three times or until it succeeds:

local tries = 0
local success, errormessage
repeat
     success, errormessage = pcall(function()
          --save the data
     end
     if success then
          print("success!")
          break
     else
          print("errormessage: "..errormessage)
     end
     wait(2)
     tries = tries + 1
until success or tries == 3

EDIT: Added a wait :)) remember to have the wait
EDIT: I made it actual code after Luka_Gaming07 showed me how, with my earlier recommendations of repeating it 3 times or until it works

1 Like

U should save the data in the ProcessReceipt callback, and return the appropriate value for wether or not it successfully saved

1 Like

Could you explain me what is ProcessReceipt? I have never heard about it.

Its a callback that handles developer products.

2 Likes

Tell me if this works for you, thanks!