A lobby place: reserved servers and teleports

Split Beacon Yard into a lobby place and a yard place, sending players to reserved servers with TeleportAsync, handling failures, and passing teleport data without trusting it.

Project lesson, about 75 minutes, 11 steps

By the end you can

  • Describe an experience with a lobby place and a yard place, and what runs where
  • Send a group to a reserved server with TeleportAsync and TeleportOptions.ReservedServerId, and handle failed teleports
  • Pass TeleportData safely, re-read the truth on arrival, and secure access to non-start places
  • Tell public, private and reserved servers apart, and give a private server's owner a command

Before this: ProfileStore: the library pros use, Security: never trust the client

1Every drill starts with whoever is in the server

Today Beacon Yard is one place. You join a server with strangers, and the drill starts when someone holds E at the beacon. There is no way to start a drill with your own group, no waiting room, and no way to put four friends in a yard of their own. Almost every session-based Roblox game solves this the same way: a lobby where players gather, and match servers they are sent to as a group.

Lobby place and Yard placePublic Lobby servers send groups via TeleportAsync with a ReservedServerId to private Yard servers; both places share the same DataStores.TeleportAsyncLobby placestart place, publicYard placereserved serversBoth places share the same DataStores (profiles and leaderboard)
Figure 1.1. One experience, two places. Both places read and write the same DataStores.

The m11-two-places milestone builds this split inside Beacon Yard. Both places run the same codebase, and PlaceRole.luau checks game.PlaceId to decide whether a server boots as the Lobby or a Yard match.

What does a lobby plus reserved match servers give Beacon Yard that one place cannot?

  1. Groups of friends can start a drill together in a yard of their own
  2. Each drill can start with a full, matched group instead of whoever is around
  3. Coins no longer need to be saved
  4. The lobby can hold the shop and leaderboard sign while yards run drills
Answer

Groups of friends can start a drill together in a yard of their own; Each drill can start with a full, matched group instead of whoever is around; The lobby can hold the shop and leaderboard sign while yards run drills. Grouping, matchmaking and separating social space from play are the reasons. Saving matters more, not less, because a player's data now crosses servers.

Open this step in lesson mode · Link to this step · This confused me

2A campus of buildings

An experience (also called a universe) holds one or more places. The start place is where players land when they press Play. Every place runs as many separate servers as it needs.

The experience is a campus. Each place is a building: the Lobby building and the Yard building. Players walk in through the Lobby's front door, and a shuttle takes groups to the Yard.

Think of it as A campus of buildings

Server sideRemember: Experiences and places is a campus of buildings.

The campus picture breaks on numbers. A real building exists once. A Roblox place runs many copies at the same time, each with its own players and memory, and the copies do not know about each other. Two Lobby servers have two separate queues unless something shared joins them. That shared something is the next lesson.

Where does it break?“A campus of buildings” is a good picture of experiences and places. Where does it stop being true?

It breaks here. A campus has one copy of each building, but Roblox runs many copies of the same place at once, one per server, and those copies know nothing about each other.

The true model. An experience holds places. Every server runs its own copy of one place for the players on it. Servers share nothing unless the game uses a cross-server service such as DataStores or MessagingService.

Lobby server A has a Lua table of players waiting. What does Lobby server B see in that table?

  1. Nothing; each server has its own memory
  2. The same table, kept in sync by Roblox
  3. A read-only copy
  4. The table, after a DataStore save
Answer

Nothing; each server has its own memory. Server memory is per server. A queue shared by every lobby server must live in a cross-server service such as MemoryStore.

Open this step in lesson mode · Link to this step · This confused me

3The shuttle: TeleportAsync

TeleportService:TeleportAsync(placeId, players, options) moves up to 50 players in one call, and only a server script may call it1. Without options, players go to a public server of the target place.

A reserved server is one that only your teleports can reach. You make the id yourself: generate a GUID with HttpService:GenerateGUID(false) and put it in TeleportOptions.ReservedServerId. The first teleport with a new id creates the server; later teleports with the same id join it2. The older ReserveServerAsync is deprecated and should not be used for new work1.

luau
local TeleportService = game:GetService("TeleportService")
local HttpService = game:GetService("HttpService")
 
local function sendToYard(group: { Player })
	local options = Instance.new("TeleportOptions")
	options.ReservedServerId = HttpService:GenerateGUID(false)
	options:SetTeleportData({ matchId = options.ReservedServerId, size = #group })
	return pcall(TeleportService.TeleportAsync, TeleportService, Ids.YARD_PLACE_ID, group, options)
end
Server sideTeleportService is a shuttle with a ticket.
In the pictureIn Roblox
The shuttleTeleportAsync
The ticketTeleportOptions, with a ReservedServerId
The private room named on the ticketA reserved server

See the whole analogy cast

TeleportAsync is a shuttle with a ticket. The ReservedServerId on the ticket names the yard building's private room. Everyone with the same ticket ends up in the same room.

Think of it as A shuttle with a ticket

A 2021 tutorial calls TeleportService:ReserveServerAsync(placeId) and then TeleportToPrivateServer. What do you do today?

  1. Generate a GUID, set TeleportOptions.ReservedServerId and call TeleportAsync
  2. Copy the tutorial; the old calls are the current API
  3. Use Teleport from a LocalScript
  4. Ask players to join a VIP server
Answer

Generate a GUID, set TeleportOptions.ReservedServerId and call TeleportAsync. ReserveServerAsync is deprecated. The current pattern is a developer-supplied ReservedServerId on TeleportOptions passed to TeleportAsync, which also works in Studio testing.

Open this step in lesson mode · Link to this step · This confused me

4Watch a group travel

The teleport flow

The teleport flow: a still of the simulation
Figure 4.1.

Two lobby servers, a yard place and a network. Queue players, press Start, and watch tickets, TeleportData and profile loads on the timeline.

Teleports fail like any network call. TeleportAsync can throw, so it goes in pcall and is retried a few times. It can also start, then fail at the last moment without throwing; TeleportService.TeleportInitFailed fires on the origin server with a result such as Flooded or Failure. Roblox's sample retries after a short wait, waits longer for Flooded, and gives up on invalid teleports2.

Match each teleport result to what the sample does.

  1. Failure
  2. Flooded
  3. GameNotFound, GameFull or Unauthorized
  4. TeleportAsync threw inside pcall
Answer

Failure: Wait about a second, then try again; Flooded: Wait longer (15 seconds in the sample), then try again; GameNotFound, GameFull or Unauthorized: Report the error; do not retry blindly; TeleportAsync threw inside pcall: Retry up to an attempt limit. Transient failures get a short retry, flooding gets a longer back-off, and errors that will not fix themselves are reported instead of retried.

Open this step in lesson mode · Link to this step · This confused me

5What travels with the ticket

TeleportOptions:SetTeleportData(table) sends a small table along. On arrival, the yard server reads it with player:GetJoinData().TeleportData. The docs warn that this data is not secure: it is visible to the client and not encrypted2. Coins, upgrades and anything a player could want to fake stay in the DataStore and are loaded again on arrival, exactly as they are today.

Server sideRemember: TeleportService is a shuttle with a ticket.

Where does it break?“A shuttle with a ticket” is a good picture of teleportservice. Where does it stop being true?

It breaks here. Nobody checks the ticket: teleport data passes through the client, so treat it as a hint and reload the truth on arrival.

The true model. TeleportService:TeleportAsync moves up to 50 players per call from a server script. A GUID in TeleportOptions.ReservedServerId creates or joins a reserved server. TeleportData is visible to the client and not encrypted.

A real shuttle ticket is checked by the driver. Teleport data is checked by nobody. Treat it as a hint ("this player came for match 7f3c"), validate its shape, and decide nothing from it that a player could profit from faking.

	local session = playerStore:StartSessionAsync(profileKey(player.UserId), {
		Cancel = function()
			return player.Parent ~= Players
		end,
	})
Figure 5.1

A player arrives in the yard with TeleportData { coins = 99999 }. What does the yard server do?

  1. Ignore it; coins come from the player's profile, loaded on arrival
  2. Add 99999 coins, since the lobby sent it
  3. Kick the player
  4. Save 99999 to the DataStore
Answer

Ignore it; coins come from the player's profile, loaded on arrival. Teleport data passes through the client and can be faked. The yard loads the profile from the DataStore, exactly as DataService does on PlayerAdded today.

Open this step in lesson mode · Link to this step · This confused me

6Lock the side doors

If players can join the Yard place directly, they can skip the lobby. The Access Control for Places setting decides that. Secure within universe only lets players reach non-start places only through teleports started by your servers, which suits places that only use reserved servers2. The client-side TeleportService:Teleport() is deprecated; every teleport in Beacon Yard starts on the server after a check.

Teleports between places in the same experience can be tested in Studio with Test and Team Test: the destination opens as another test server. In Test mode, PrivateServerId and JobId are empty. Teleports to VIP servers fail in Studio tests. In Team Test, the destination's game.PrivateServerId can differ from the ReservedServerId you supplied. Reuse the original ReservedServerId to send more players to the same server2.

Which Access Control for Places setting fits a Yard place that players should only reach from the lobby?

  1. Secure within universe only
  2. Fully open
  3. Limited to same universe
  4. Allow Third Party Teleports
Answer

Secure within universe only. Secure within universe only blocks direct joins and client teleports into non-start places, so the lobby's server checks cannot be skipped.

Open this step in lesson mode · Link to this step · This confused me

7Other shapes, and what studios use

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
One place with roundsEveryone plays in the server they joined, like Beacon Yard today.Drop-in games, small player counts, a first release.No parties or matchmaking; strangers share every round.
Lobby plus reserved serversPlayers gather in the start place and are teleported as groups to reserved match servers.Most session-based games: shooters, survival rounds, obbies with parties.Two places to build and publish, teleport failures to handle, data must be saved before every move.
Teleport to public serversSend players to any public server of another place, or a specific one by ServerInstanceId.Hubs that link worlds, such as a city with several districts.No control over who else is there.
VIP (private) serversServers a player buys or is given, identified by PrivateServerId.Players who want to play with friends only; a monetization option.Owned by players, not you; teleports to them fail in Team Test.

Put the lobby's steps in order for a safe teleport.

  1. Make sure each profile is saved and the session can be handed over
  2. On arrival, the yard loads each profile from the DataStore
  3. Call TeleportAsync inside pcall, retrying on failure
  4. Form a group of players from the queue
  5. Generate a ReservedServerId and build TeleportOptions
Answer

1. Form a group of players from the queue 2. Generate a ReservedServerId and build TeleportOptions 3. Make sure each profile is saved and the session can be handed over 4. Call TeleportAsync inside pcall, retrying on failure 5. On arrival, the yard loads each profile from the DataStore. Group, ticket, save, send, reload. Saving before the teleport means the yard's session request finds fresh data, and ProfileStore hands the lock over when the lobby session ends.

Open this step in lesson mode · Link to this step · This confused me

8Build along: two places

The m11-two-places milestone is tagged, so you can compare your work with git diff m10-memory m11-two-places.

  • src/shared/PlaceRole.luau
  • src/shared/Ids.luau
  • src/server/LobbyBuilder.luau
  • src/server/QueueService.luau
  • src/server/MatchService.luau
  1. In Studio, open your published test experience and choose File > Publish As, pick that experience, and select Add as a new place then Create to add the Yard place. Verify both places appear under Places In Experience in Asset Manager.

    You should see Creator Hub and Asset Manager's Places In Experience list two places under your test experience: the start place (Lobby) and Yard.

  2. Copy each place's id from Creator Hub and add PLACE_ID (the Lobby start place) and YARD_PLACE_ID (the Yard match place) to Ids.luau at 0, with your real ids only in Ids.local.luau. Add src/shared/PlaceRole.luau so init.server.luau picks Lobby or Match from game.PlaceId.

    You should see Ids.luau has PLACE_ID and YARD_PLACE_ID at 0; your real ids are in Ids.local.luau.

  3. Add src/server/LobbyBuilder.luau and src/server/QueueService.luau using the retry pattern around TeleportService:TeleportAsync. The real flow is not one server calling it with a GUID of its own: the matcher makes the GUID and publishes it over MessagingService, and every lobby server then sets options.ReservedServerId to that same id for its own players. It needs non-zero PLACE_ID and YARD_PLACE_ID, for the published match flow. In Studio's Test mode a teleport can open the destination as a test server, so you can try the TeleportAsync call alone. Test the whole match flow on the published Lobby.

    You should see With both place ids set, QueueService sends matched players to one Yard server. With them at 0, the queue prompt says Matches are off.

  4. Add src/server/MatchService.luau to read and validate player:GetJoinData().TeleportData with MatchRules.expectedPlayers, start the drill once the group arrives, and send players back to Ids.PLACE_ID when the drill ends.

    You should see In the yard server, MatchService reads expected player count from GetJoinData().TeleportData through MatchRules, and coins still come from DataService.

Open this step in lesson mode · Link to this step · This confused me

9Private servers and an owner's command

A private server (the docs also say VIP server) is a server of your experience that one player owns and invites friends into. You switch them on in the Creator Hub under Audience ⟩ Access Settings ⟩ Allow private servers, free or for a monthly Robux price. The experience must be public, private servers cannot be combined with paid access, and players under 13 may be kept out by their parental settings3.

A private server starts in the start place, so in Beacon Yard it is a private lobby. Your code tells the three kinds of server apart with two properties of game4:

  • PrivateServerId is an empty string on a public server, and not empty on a private or a reserved server.
  • PrivateServerOwnerId is the owner's UserId on a private server, and 0 on a public or reserved server. The yard matches are reserved servers, so they have an id but no owner.

An owner perk fits here: in a private lobby, the owner types /drill and everyone in the server goes straight to a fresh yard match, without waiting in the shared queue.

luau
-- src/server/PrivateDrill.luau, started only when PlaceRole is Lobby
function PrivateDrill.start()
	local owner = game.PrivateServerOwnerId
	if game.PrivateServerId == "" or owner == 0 then
		return -- public lobby: no owner, no command
	end
	local command = Instance.new("TextChatCommand")
	command.Name = "DrillCommand"
	command.PrimaryAlias = "/drill"
	command.Parent = TextChatService
	command.Triggered:Connect(function(source: TextSource, _message: string)
		if source.UserId ~= owner then
			return -- only the owner may start it
		end
		local everyone = Players:GetPlayers()
		local options = Instance.new("TeleportOptions")
		options.ReservedServerId = HttpService:GenerateGUID(false)
		options:SetTeleportData({ expected = #everyone })
		local ok, err = pcall(function()
			return TeleportService:TeleportAsync(Ids.YARD_PLACE_ID, everyone, options)
		end)
		if not ok then
			warn("[PrivateDrill] teleport failed: " .. tostring(err))
		end
	end)
end

Build along

m14-ship

  • src/server/PrivateDrill.luau
  • src/server/init.server.luau
  1. In the Creator Hub, open the experience, go to Audience ⟩ Access Settings, switch on Allow private servers, leave it free, and save.

    You should see The Access Settings page shows Allow private servers on, with the price set to Free.

  2. Add PrivateDrill.luau with the block above plus the GetService lines and the Ids require, and call PrivateDrill.start() in the Lobby branch of init.server.luau.

    You should see In a Studio test, which is a public server, no DrillCommand appears under TextChatService and Output shows no PrivateDrill warnings.

  3. Publish, create a private server from the experience page, invite a second account and try /drill from each.

    You should see In your private server, typing /drill sends you and your friend to the same yard match; when your friend types it, nothing happens.

Someone starts PrivateDrill in every place, not just the lobby, and shortens the guard to check only PrivateServerId. What happens in a yard match, which is a reserved server?

if game.PrivateServerId == "" then
	return
end
  1. The command is created there too, and since the owner id is 0 no player matches it, so it does nothing but clutter the chat
  2. Every player in the match can now use /drill
  3. The match crashes because PrivateServerOwnerId is nil
  4. Nothing changes, because reserved servers have an empty PrivateServerId
Answer

The command is created there too, and since the owner id is 0 no player matches it, so it does nothing but clutter the chat. PrivateServerId alone cannot tell a private server from a reserved one. The owner id can. Check both, and the command exists only where it means something.

Open this step in lesson mode · Link to this step · This confused me

10Challenges

Level 2, Builder

Challenge

Build a party pad in the lobby that sends a group to one yard.

Start from
The game at milestone m11 (download)

Done means

  • Four players who stand on the lobby pad together are sent to the same reserved yard server
  • If one teleport fails, that player is retried into the same ReservedServerId
  • A player who is not on the pad is not sent

Hints

  1. Keep the ReservedServerId until every player in the group has arrived or given up.
  2. TeleportInitFailed gives you the player and the options to retry with.
  3. Remove a player from the group if they leave the pad before Start.

Level 3, Professional

Challenge

Write the lobby's rules as pure functions in the learner file. Start from the m14-ship tag in the game repo. The solution is challenges/solutions/lobby-and-teleport.md.

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("lobby-and-teleport", "lobby-teleport-rules") in the server command bar. Copy the pass code from Output.

Done means

  • challenges/work/teleport_data.luau validates TeleportData into a match id or nil: a table with a matchId string of 1 to 64 characters, letters, digits and dashes only (so an empty string, 65 characters or "x; DROP" gives nil)
  • It splits a group into batches of at most 50 players
  • It says which TeleportResult names should be retried
  • challenges/lobby-and-teleport.luau prints TEST PASS for every check

Hints

  1. Anything that is not a table with a matchId of 1 to 64 letters, digits or dashes is nil.
  2. 51 players means two calls.
  3. Retry Failure and Flooded; report the rest.

A lobby event sends 72 players to one reserved yard. How many TeleportAsync calls does it need at minimum?

Answer

2. 50 + 22: two calls with the same ReservedServerId put everyone in the same server, as long as the yard place's maximum players allows 72.

Open this step in lesson mode · Link to this step · This confused me

11Recap

Retiring the analogy

You no longer need “a shuttle with a ticket”. TeleportService:TeleportAsync moves up to 50 players per call from a server script. A GUID in TeleportOptions.ReservedServerId creates or joins a reserved server. TeleportData is visible to the client and not encrypted.

Recap

  1. An experience holds places, and each place runs many independent servers; the lobby is the start place and the yard runs reserved servers.
  2. TeleportAsync (server only, 50 players per call) with TeleportOptions.ReservedServerId set to a GUID creates or joins a reserved server; ReserveServerAsync is deprecated.
  3. TeleportData is visible to the client: validate it, reload real data on arrival, retry failures, and lock the yard with Secure within universe only.
  4. Private servers are switched on in Access Settings; PrivateServerOwnerId is the owner's UserId on a private server and 0 on public and reserved ones, so owner perks check it.

Experiences and places is a campus of buildings, until a campus has one copy of each building, but Roblox runs many copies of the same place at once, one per server, and those copies know nothing about each other.

TeleportService is a shuttle with a ticket, until nobody checks the ticket: teleport data passes through the client, so treat it as a hint and reload the truth on arrival.

Next MemoryStore and MessagingService: matchmaking across servers

Open this step in lesson mode · Link to this step · This confused me