How to teleport to a private game?

I want a group of players to be teleported to a subgame, but I don’t a different group to be teleported to the same server after that, (kinda like doors, where you cannot join someone elses game.) But it keeps giving this error. Also this is still in testing fazes so I don’t want it to be public to the world yet.

image

local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local textLabel = workspace.Sign.Text.SurfaceGui.Frame.TextLabel
local zone = script.Parent --// the part encasing the floor pad
local timer = 30
local PlayerTable = {}

while task.wait(1) do
	PlayerTable = {}
	timer -=1
	print(timer)
	textLabel.Text = ("Boat Departing in "..timer)
	if timer == 0 then
		timer = 0

		local parts = workspace:GetPartsInPart(zone) --// get the parts inside of the zone
		for _, part in parts do
			local model = part:FindFirstAncestorOfClass("Model") --// check if the character model exists
			if model and model:FindFirstChildOfClass("Humanoid") then --// check if the model has a humanoid

				local player = PlayersService:GetPlayerFromCharacter(model) --// check if the character is a player
				if player and table.find(PlayerTable, player) == nil then
					table.insert(PlayerTable,player) --// add them to the table
				end

			end
		end
		if #PlayerTable > 0 then
			TeleportService:TeleportAsync(teleportID, PlayerTable) --// teleport them

		end
		
		task.wait(1)
		timer = 30 -- restart the cycle
	end
end

game:BindToClose(function()
	local PlayerTable = game:GetService('Players'):GetPlayers()
	TeleportService:TeleportAsync(teleportID, PlayerTable)
end)

Private servers, TeleportService has a method called TeleportToPrivateServer that teleports an array of players to a server that is reserved exclusively for them.

Basically you reserve a server using TeleportService:ReserveServer(placeId) which returns a private server key, and then pass that as a parameter when using TeleportToPrivateServer.

1 Like

okay thanks for solving that, now how do I get make the teleport work? Do I need to publish the game?

Teleporting only works in game, so yeah you need to publish & test there :grin:

1 Like

error
HTTP 403 (Forbidden) - Server - Teleport:30
I tested it in a published private game and it did not work. It comes from serverscript service.

local PrivSID = TeleportService:ReserveServer(teleportID)
			TeleportService:TeleportAsync(PrivSID, PlayerTable) --// teleport them

You need to use TeleportService:TeleportToPrivateServer()

1 Like
local PrivSID = TeleportService:ReserveServer(teleportID)
	TeleportService:TeleportToPrivateServer(PrivSID, PlayerTable)
1 Like

Still the same error and in the game nothing happens

Because it is wrong. The correct usage is this:

local PrivSID = TeleportService:ReserveServer(teleportID)
	TeleportService:TeleportToPrivateServer(teleportID, PrivSID, PlayerTable)

First parameter is game ID, second parameter is the private server code and the third parameter is players to teleport table.

1 Like