Hey guys, it’s agKing here, and I have a question regarding server behavior when no players are left in the game.
I’ve always wondered what exactly happens when the last player leaves the game. Does the server automatically shut down?
From my experience, it seems like the server shuts down and reinitializes the game to its default state. However, I’m trying to test server-client communication with multiple players (e.g., Player1, Player2, Player3), and I want to understand how this works when there are no players left on the server. I want to use server testing in a scenario where players aren’t already present (like in the default “agKing” test player setup).
So, I tried using game:Shutdown() when no players are left, but I encountered a bit of latency when checking if there are still players remaining.
Here’s the code I’m using:
self.playerRemovingConnection = game.Players.PlayerRemoving:Connect(function(player)
print("PLAYER : ", player, " HAS BEEN REMOVED")
self:removeParticipants(player)
if #PlayerService:GetPlayers() == 0 then
print("No player left on the server")
else
print("Number of player left in this server : ", #PlayerService:GetPlayers())
end
end)
The issue I’m facing is the latency when checking if no players remain in the server after one player leaves. I want to make sure the server properly recognizes when there are no players left and shuts down or reinitializes.
Additionally, I noticed that the map for the game mode was still created, even though no players remained in the game. I’ve recorded this behavior in a video to provide proof of this issue.
Has anyone else faced this issue or found a workaround for testing scenarios like this? Any help or insight would be greatly appreciated!
Yeah but how does that work BindToClose what I’m saying is that when all the player left the game the server state shouldn’t keep going I want to be able to shutdown the game and reinitialize so the next time the first player get in the game state is back to default to avoid bug issues about remote events, maps cloning etc.
Uhh, that shouldn’t ever be an issue to my knowledge. When a game is about to shut down, no players can join it. They’re sent to a new, different server. This is just what I know. Potentially, I suppose, there could be a miniscule window where a player joins the second before the otherwise final player leaves, but that’s such a low likelihood that it isn’t even really worth your time to consider, let alone act upon.
Yeah but why when I’m testing with multiple players like (Player1, Player2, Player3, Player4) when the last player left the state of the game I still see it run in the background ?
Nope. That’s just because you’re testing in Studio, which is not a perfect mimic of the actual Roblox client. The only reason you still see a server open is because instead of the game shutting the server down, you have to instead. In a real game, that’ll never be an issue.