Is BindToClose necessary?

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?

Any replies are appreciated!

2 Likes

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.

3 Likes

It’s not necessary but it is highly recommended as things such as if the server crashes, it doesn’t count as PlayerRemoving and wont fire it.

3 Likes

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?

2 Likes

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)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.