New players joining a server after everyone left?

I’m working on a game loop (minigame loop) and right now I wait for the first player to join and then I begin it (so I don’t start the game if I’m in run mode in studio, or if the first player is still loading)

I want to stop the game loop whenever the last player leaves, and put the game back into an inactive state

The reason for this is so the game doesn’t try to load minigames when there is no one to play them

Would it be necessary to have code to restart the game loop (if another player joins) after the last player leaves, because I’m unsure if a player could join in between the time the last person leaves and the time before the server shuts down?

this is just a possible edgecase im worried about

Since it takes around half a minute for a game to completely shutdown, there’s a slight possibility that players could join a game that’s about to shutdown. You should add checks if there’s at least 1 or more players in game or teleport new players to another server.


Do you have functions in your :BindToClose() yielding 30 seconds? Because that’s the maximum allotted time before the server forces a shutdown.

I don’t have any BindToClose functions currently, the issue here was that I needed to know if I should have code to resume the minigame loop after the last player leaves, and someone joins within that little time window

1 Like