I wanna save player data incase of server shutdown
It works for update shutdown but server shutdown doesn’t give enough time to save player data
(Yes my save system works fast it just needs couple seconds)
game:BindToClose(function(Reason)
for int, player in ipairs(Players:GetPlayers()) do
task.spawn(function()
SaveSlot(player)
end)
end
end)
game:BindToClose(function(Reason)
for int, player in ipairs(Players:GetPlayers()) do
task.spawn(function()
SaveSlot(player)
end)
end
task.wait(10) -- Force a wait so that everything is saved.
end)
Wow I didn’t know you can wait up whole server i thought BindToClose function was like connect event before server goes in shutdown Thanks! you are lifesaver
You’re welcome, it works like a waiting function. You can connect multiple BindToClose functions, and the server will close after all BindToClose functions have finished, but there is a time limit, if I’m not mistaken it’s 30 seconds.