How many attempts should you try to save player data?

Player data saves when one of these happens:

  • They leave the game
  • BindToClose
  • AutoSave (every 5 minutes)

Currently the game saves the player data once, it doesn’t attempt to save it several tries until it’s either failed or is success. It just saves it in the pcall.

pcall(function()
	CashStore:SetAsync(player.UserId, Cash.Value)
end)

Should I have attempts?

local tries = 0	
local success
repeat
	tries = tries + 1
	print("saving data: "..player.Name.."-"..player.UserId)
	success = pcall(function()
		CashStore:SetAsync(player.UserId, Cash.Value)
	end)
	if not success then wait(1) end
until tries == 10 or success 
if not success then
	warn("Cannot save data for player!: "..player.Name.."-"..player.UserId)
	--pfolder:Destroy()
else
	print("Data has been saved successfully!: "..player.Name.."-"..player.UserId)
	--pfolder:Destroy()
end

Is it advisable? If so, how many attempts should it be?

The magic number for me honestly is just 3. If you retry like more than 5 times and it’s still failing then the data stores are down and you can’t save the dats regardless so there’s no point in too much retrys. Yes it’s advisable.

3 Likes

Thanks for the response, I’ve decided to do the magic number like you said, 3 times.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.