I have 4 ordered datastores for leaderboard stats and I’m trying to save player’s data after the server shut down. I’m worried that it might throttle.
Here’s how I normally save data when the server shuts down:
game:BindToClose(function()
-- repeat these for loops 4 times for every ordered datastore
for _, player in pairs(game.Players:GetPlayers()) do
-- save data
task.wait(1) -- to prevent throttling
end
for userid, data in playerLeftCache do
--save data here aswell
task.wait(1) -- to prevent throttling
end
task.wait(10) -- to prevent throttling
end)
The problem now is that there’s a shutdown deadline, so the code can’t run for 40+ seconds.
I have a while true loop that saves all player’s ordered datastore data including the cached data of players who left the game after the last saving iteration.
When the last player leaves the game, the server shuts down, triggering BindToClose
. If I only save that player’s data, it wouldn’t be a problem, but I have a cache of all the players who left after the last regular save loop, which means I also have to save their data. This is where I’m worried about throttling, because I have to save multiple player’s data for multiple datastores at once.
I could save all ordered datastore data after the player leaves, but that would also cause issues with throttling.
Is there a way of saving 4 ordered datastores for every player after shutdown without throttling or hitting the shutdown deadline?