Suppose a player's data is saved upon leaving. After retrying many times (5 times or more) to save their data via DataStoreService, the data still fails to save. What should I do? Cross my fingers that this never happens? If anyone else has taken into consideration this problem, have you taken any precautions for a situation like this? I'm hoping to get several potential workable solutions since to me it seems that there's no cure-all for this problem.
Here's some fake code modeled after the real code I'm using if needed:
function SaveData(params)
local success, value = pcall(function()
DataStore:SetAsync(params.key, params.value)
end)
if not success then
warn('could not save data')
-- still some attempts left
if params.attempts > 0 then
wait(params.retryInterval)
params.attempts -= 1
return SaveData(params)
-- data could not be saved after exhausting all attempts
else
return false
end
else
-- data was saved, return true
return true
end
end
Players.PlayerRemoving:Connect(function(player)
local success = SaveData({
attempts = 5,
retryInterval = 3,
key = player.UserId,
value = player.Points.Value
})
if not success then
-- what now?
end
end)

1 comment
This is one of the best answers I've seen on this website so far. You bring up a lot of great points. Thank you!