Right now I use an autosaver system that occurs every 60 seconds, but when I shutdown data is rerolled 60 seconds back and a lot could happen within that period (such as gaining something rare). I have heard of BindToClose() before but I haven’t looked into it. But after realising people complaining about losing a minute of data, I was suggested to use BindToClose(), so I have a few questions:
How do I use BindToClose() exactly? In the Dev Hub, there’s an example:
Are the players kicked from the game where it says print(2*2) or are they still in the game until print(“Done”) is reached?
If I increase the length the wait(3) to lets say 30 seconds, is there a chance that players when shutdown can rejoin the same server since technically the server is still alive?
If I use a loop within BindToClose() to save every players data, should this cause queues and possible data failures? Should I use wait(2) per iteration, note that my main save data function uses OrderedDataStores for leaderboard stuff, I could potentially just add a BoolValue to indicate if it’s necessary to save data to the leaderboard since leaderboards only reflect what the players data is, so next time they do appropriately save, they will appear.
With BindToClose() being added, should I remove this 60 seconds autosaver feature? Since let’s say for example, data could have been saved 2 seconds ago, and then the BindToClose function could cause redundant saving, I could perhaps add a tick() value just to see how long ago data was saved for that player.