Datastore2 shutdown servers not saving data

So currently my datastore2 bindtoclose is not working. Everytime I shutdown the server many people lose data upon re-joining after shutdown. There are no errors and nothing in output (since I cannot see console when server has shutdown). PlayerRemoving event fires just fine and everything saves when the player leaves but not when game shutdowns.

	for _, player in ipairs(game.Players:GetPlayers()) do

Btw saveData function saves all the data for the player.

If you cannot see a log in your console after server shutdown, then the event/coroutine has not been executed.
Honestly I’ve never used such event, there’s no real use-case for that.

If you want to save user data after user’s disconnect, then do it in proper event. If you want to make some kind of finalization after server shutdown, then you should be having a function, where you:

  1. Save all player data
  2. Kick all players from the server
  3. Kill the server

Also important to mention that coroutines are asynchronous threads, which always waits at least one frame before they’re executed, so running them inside a server shutdown event is too late. It’s better to just invoke your function saveData which will definitely lock main thread until everything is done, and so server will not shutdown until main thread finishes its work.

Im using the roblox option where it shutdowns all the servers

Screenshot (36)

Not entirely true for the case when a developer shuts down all servers as dchin says. But also when Roblox loses it servers during an outage, you have no control over when this will happen or the ability to manage the order of events. BindToClose() is there to stop data-loss under these circumstances by sending as much data as possible before the server dies.