Why this line doesnt work?

Hi,
I am learning how to work with teleport service and I was executing this line:

game:GetService("TeleportService"):TeleportToPrivateServer("4288429706",code,game.Players:GetPlayers())

and it gived this error:


(i executed it 2 times, the error will show 1 time per execuing this line).
How to solve it?

The first argument (place ID) must be a number.

TeleportToPrivateServer Parameters

Name Type Default Description
placeId int64 The ID of the place to teleport to
reservedServerAccessCode string The reserved server access code returned by TeleportService:ReserveServer
players Objects An array of Players to teleport
spawnName string Optional name of the SpawnLocation to spawn at
teleportData Variant Optional data to be passed to the destination place. Can be retrieved using TeleportService:GetLocalPlayerTeleportData
customLoadingScreen Instance nil Optional custom loading screen to be placed in the CoreGui at the destination place. Can be retrieved using TeleportService:GetArrivingTeleportGui

A) I have same id in reserve server and it works
B) I removed " and still same error


You forgot this.

Here’s the example code on the Wiki.

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

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

1 Like

Is the code variable a string? Do you mind sharing your code with me so I can take a look at the full script?

local code = game:GetService("TeleportService"):ReserveServer(4288429706)
game:GetService("TeleportService"):TeleportToPrivateServer(4288429706,code,game.Players:GetPlayers())

@metryy

1 Like

Try this

local code = game:GetService("TeleportService"):ReserveServer(game.PlaceId)
game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId,code,game.Players:GetPlayers())

I am going to second place. (but same game)

ReserveServer returns a tuple with the first value being the access code. You need to make sure you’re only passing the code.

local code = table.pack(game:GetService("TeleportService"):ReserveServer(4288429706))[1]
game:GetService("TeleportService"):TeleportToPrivateServer(4288429706,code,game.Players:GetPlayers())

ok, i made mistake , that i forgot to apply edits, and i had still there bad player argument

1 Like

The table.pack isn’t necessary, since the extra values of the tuple are discarded due to having no variables to be assigned towards. Including only a single variable is sufficient enough.

In addition to this, even if both values of the tuple were passed to TeleportService, the subsequent arguments passed in there force the tuple size to 1, thus only getting the access code and discarding the ServerId.

2 Likes

Yeah, my mistake. Thanks for pointing it out, my brain wanted to think variables can hold more than 1 value because I wasn’t sure what else could be wrong with the code OP provided haha

1 Like