So, I have 4 ordered datastores that store leaderboard values for players, but I’m worried that if I do SetAsync
on all of them at once (when the player leaves) it’ll throttle if there are many players in the server.
Right now I’m using exponential backoff and task.wait()
in between SetAsync
s, but I don’t know if this is the right way of doing things.
function exponentialRetry(maxRetries: number, f: (...any) -> any, ...: any)
local retryDelay = 1
for i = 1, maxRetries do
local success, result = pcall(f, ...)
if (success) then return result end
if i < maxRetries then
task.wait(retryDelay)
retryDelay *= 2
end
end
end
-- when player leaves:
exponentialRetry(10,function()
DS1:SetAsync(tostring(player.UserId),data1)
end)
task.wait(1)
exponentialRetry(10,function()
DS2:SetAsync(tostring(player.UserId),data2)
end)
task.wait(1)
exponentialRetry(10,function()
DS3:SetAsync(tostring(player.UserId),data3)
end)
task.wait(1)
exponentialRetry(10,function()
DS4:SetAsync(tostring(player.UserId),data4)
end)
Is there a better way of doing this to prevent throttling? Any help would be appreciated.