Hello devs,
I was wondering how would I detect when a server closes? Please tell me if this isn’t the appropriate category!
Hello devs,
I was wondering how would I detect when a server closes? Please tell me if this isn’t the appropriate category!
Done. But what about how would I detect whens a server closes?
I think BindToClose would help you with this.
game:BindToClose(function()
print("Game is shutting down.")
end)
To detect when a server closes I would just use the PlayerRemoving() event and each time the event occurs, I would check the amount of players that are still in the game.
NOTE: I believe there is possibly a more efficient way to do this.
I actually want to detect when a server closes for a server ban thing, so I can unban them each time. So do I just unban them when the player number is 0?
Last thing, how would I check how much players are there?
I believe you would do something like this:
#game.Players:GetChildren
local players = game:GetService("Players")
local playerCount = #players:GetChildren()