How to use :ReserveServer() to make a lobby system?

Firstly, I apologize if this is the wrong category, I just felt this was the best category to ask this. Secondly, I want to make a lobby system where players create a private lobby and then are teleported to a copy of place I created inside the experience to play a private game/round with their friends and someone told I could achieve this by using :ReserveServer(), but the Developer Forum only talks about how to use it to teleport players to private servers. Can anyone tell/show me how to use the function or if there is another function I can use to achieve this? Thank you!

8 Likes

I can show you how to use ReserveServer()
Basically, we use reserve server to get a server that is private only to the people that are getting teleported into it. Their friends will not be able to join. Inside the parentheses, we put the game Id that we want to reserve a server from. Usually, I create a variable to store the new server like you see in the example below me.

local TPS = game:GetService("TeleportService") -- We get teleport service

local AccessCode = TPS:ReserveServer(58392387) -- Inside here, you put the ID of the game you want to create a server for.

For this example, I’ll be teleporting a group of players into a private server. This is very similar to when teleporting a single player.

local PlayerTable = {} -- Make a table for players

for _, player in pairs(game.Players:GetPlayers()) do
  table.insert(PlayerTable, player) -- For each player, we'll insert them into the table.
end

TPS:TeleportToPrivateServer(58392387, AccessCode, PlayerTable) -- We teleport all the players at the same time by teleporting the table that they are in.

This is very close to the code that I have in my game.
So basically, let me explain –
We create a variable for the Teleport Service.
Next, we reserve a private server by using :ReserveServer(ID of Game)
We then create an empty table and for each player in the server, we insert them into the table.
Once we are done inserting everyone into the table, we then teleport them using :TeleportToPrivateServer(Game ID, AccessCode you got by using ReserverServer(), PlayerTable).
Using TeleportToPrivateServer(), you can perform more things such as teleporting the players with specific data such as the weapon they were holding before getting teleported (just an example).

For more information – use this.
And this.

21 Likes

https://developer.roblox.com/en-us/api-reference/function/TeleportService/ReserveServer

2 Likes

So if I reserve the server and then teleport the players, I can just reserve the server again the same way and it will be a new and exact copy of the server when I teleport a new set of players, right?

1 Like

Yes. It will reserve a new server.

2 Likes

Ok, thanks for all the help! This is exactly what I need.

1 Like

No problem! Glad I was able to help out.

1 Like