TeleportService reserve server

so i made it reserve a server but i dont know what to do after doing this in the server script. i want to make a tower defense game and this is the furthest ive gone so far

local TeleportService = game:GetService("TeleportService")

local reservedServerCode = TeleportService:ReserveServer(game.PlaceId)
print(reservedServerCode)

if you want to teleport the players to the place, you need to use TeleportService:TeleportToPrivateServer. what you need for the parameters for this function is the players you want to teleport, the :ReserveServer function (you already have that), and the placeID you want to teleport those players into.

here’s an example: this is from the wiki, so check it out if you need to : D

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local Code = TeleportService:ReserveServer(game.PlaceId) -- returns a code
local Players = Players:GetPlayers()

TS:TeleportToPrivateServer(game.PlaceId,Code,Players) -- this teleports the player into the game you specified
1 Like

i tried it and it gives this error in testing:

Can you post your current script?

local TeleportService = game:GetService("TeleportService")

local Code = TeleportService:ReserveServer(game.PlaceId) -- returns a code

local Players = game:GetService("Players")

local players = Players:GetPlayers()

TeleportService:TeleportToPrivateServer(game.PlaceId,Code,players) -- this teleports the player into the game you specified

Is that your entire script? If so, the script will run instantly when the game starts, and the players array will be empty.

2 Likes

i added a wait(5) just now and its still giving the same error

Where did you add the wait function?

above :TeleportToPrivateServer() function

do i need to put it before the variables

I would put it at the top or at least before you do Players:GetPlayers().

1 Like

okay i moved it higher up and it worked thank you!!

1 Like