When I first learned datastores, I was told that a :BindToClose function was necessary to save data alongside a PlayerRemoving event. Is this true? When does :BindToClose function run? Wouldn’t all of the players had to have already left and therefore trigger the PlayerRemoving event for this to happen?
BindToClose fires when a game server is in the process of shutting down.
You would use it with your data saving medium to save data for each player. What’s useful is that BindToClose yields for up to 30 seconds for any function bound to it to finish executing, so you can use that to guarantee some sort of handling for each player before the game server shuts down.
So it is useful to run a function that saves the data of all players remaining in the game in a BindToClose function to ensure data save in case of a server failure correct?
Would an autosave feature would also help prevent data falures?
Yes. Autosaves would also help; binding a function to BindToClose is just a way of ensuring data validity in the event of something unexpected like a server crash (which does trigger BindToClose)