Catch-All PlayerAdded / PlayerRemoving Functions Module

Hmmm, I was under the impression that BindToClose always runs when the server closes regardless of why. It appears that’s just the player specifically, so the only way you’d be able to save data regardless of crashes would be to have an auto-saving loop every minute or so. Though the point made in that post is in conflict with the post directly below it, which states that PlayerRemoving is in fact reliable.

I’m not sure who’s right here, and considering that it’s a pain to test with these things (can’t read print statements run in BindToClose functions because, well, the server window [including the output] closes), I’ll just keep this code as is. The way it works is that the connected function for PlayerRemoving and the loop that runs this same function on each player in BindToClose both actually check if the other event has already been run for a given player, so no function you assign for leaving the game will ever be run twice on a single player here. I should also note that the table storing each player’s boolean values (for whether the removing function has already been run on them) uses the player instance as the index, so this would not cause a failure to save should they rejoin the same server and then leave again.

Later edit: here’s what I was talking about with regards to PlayerRemoving being unreliable.