Teleporting back to same lobby server

In my game, it teleports you to a private server map for the round system, then teleports you back to the main place.

However, I want all the players to tp back into the same exact server from which they came from. How would I go about this? What if the server doesn’t exist anymore?

Code examples would be helpful.

Thanks for reading :smiley:

2 Likes

In order to accomplish this, you would likely have to reserve a server not just for the private, round system server, but also for the “Lobby” server. You can use the functions of the TeleportService including the :ReserveServer() function to ensure that each are private servers. Doing it this way, however, you would need to have players first join a public “Loading” server, then teleport them to the private “Lobby” server, and then on game start teleport them to the “In Game” server - definitely doable and not as odd as it may sound. Psuedo-code:

--In "Loading Server"
game.Players.PlayerAdded:connect(function(player)
    --Reserve a private server for this player
    --Teleport specifically (not all players in game) this player to their private "Lobby" server
end)

--In "Lobby" Server
--TODO:
    --A way to invite players or join friends private "Lobby" servers.
PATH.OnGameStart:connect(function()
    --Reserve a private server for the "In Game"
    --Teleport all players in the current private "Lobby" to this new private server
end)

--In "In Game" Server
--wait for all players to join the game (with timeout in case of errors)
runGame()
--teleport all players back to the private "Lobby" server they came from.
--This means you will need to store the server access code and the PrivateServerId of the "Lobby" from which they came

Let’s say a random player pressed pressed play on the game, would they be able to join that server? I don’t want the server to be exclusive to only the players who joined that game. And when I said they teleported to a private server I mean a reserved server for the players that were queued in the lobby, which is already made and working.

Haha, sorry, which server are we talking about now? It may also help if you could clarify or describe what sort of server system you’re trying to make. For example, the way I described would be good for if you wanted custom private lobbies for friend groups that then join a closed lobby which only they will have access to. If you want something more akin to a Battle Royale with Duos or Squads type teams, then lmk.

Well, the game is a battle royale. I don’t want any of the lobby servers to be closed servers. The round system servers are not the lobby, but a place under the lobby game, which the lobby teleports you to that place, and those are closed servers.

Ok, so under that scheme your problem area is getting the players in the closed “In Game” servers back to the same lobby. From what I can think of right now there’s no particularly “good” way to allocate lobbies of battle-royale size. One solution would be to just teleport all players from the “In Game” server back to the public lobby place. However, you wouldn’t be able to ensure that all players from the “In Game” session make it back into the same server they came from, or even that they all go back to the same one. (This actually might be a good workaround though as it would shuffle lobbies in between game sessions innately)