PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

ReserveServer

This function returns an access code that can be used to teleport players to a reserved server, along with the DataModel/PrivateServerId for it.

ReserveServer can only be called on the server.

Reserved Servers

The following are characteristics of reserved servers:

  • They can only be accessed using TeleportService/TeleportToPrivateServer, with the access code ReserveServer returns
  • A game server is started when the access code is first used
  • Access codes remain valid indefinitely, meaning reserved servers can still be joined if no game server is running (in this case a new game server will be started)

You can see if the current server is a reserved server by using the following code:

local isReserved = game.PrivateServerId ~= "" and game.PrivateServerOwnerId == 0

The DataModel/PrivateServerId is constant across all server instances associated with the server access code, the DataModel/JobId is not.

Studio limitation

This service does not work during playtesting in Roblox Studio — To test aspects of your game using it, you must publish the game and play it in the Roblox application.

Cross-Platform Play

Players on Xbox One with cross-platform play disabled will arrive in a different server with players with cross-platform play enabled. This can cause multiple game servers with the same PrivateServerId to exist.

Parameters

Name Type Default Description

The DataModel/PlaceId of the place the reserved server is being created for

Returns

Return Type Summary

The server access code required by TeleportService/TeleportToPrivateServer and the DataModel/PrivateServerId for the reserved server


Code Samples


TeleportService: Teleport to a Reserved Server

The following code would send everyone in the current game to a reserved server. Since reserved servers can only be joined by using /TeleportService/TeleportToPrivateServer, nobody will join the reserved server afterwards.

Mind that, since everyone will be teleported, the current server will (probably) shutdown as nobody would be left in it.

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")

local code = TS:ReserveServer(game.PlaceId) -- Returns a code
local players = Players:GetPlayers() -- Get a list of all players

TS:TeleportToPrivateServer(game.PlaceId,code,players) -- Actually teleport the players
-- You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen

TeleportService: Teleport to a Reserved Server via Chat

The following code would reserve one server, if it hasn’t be reserved before. Whenever someone says “reserved”, they will be teleported to the private server.

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetGlobalDataStore()
 
-- Get the saved code
local code = DS:GetAsync("ReservedServer")
if type(code) ~= "string" then -- None saved, create one
	code = TS:ReserveServer(game.PlaceId)
	DS:SetAsync("ReservedServer",code)
end
 
local function Joined(plr)
	-- Everytime they chat, we want to know
	plr.Chatted:Connect(function(msg)
		if msg == "reserved" then -- Aha, that's our cue
			TS:TeleportToPrivateServer(game.PlaceId,code,{plr})
		end
	end)
end
 
-- Connect all current and future players
Players.PlayerAdded:Connect(Joined)
for k,v in pairs(Players:GetPlayers()) do
	Joined(v)
end