:TeleportToPrivateServer error?

Code:

local TeleportService = game:GetService("TeleportService")

local placeId = 2558455770

local reservedServer = TeleportService:ReserveServer(placeId)

local TheDudes = game.Players:GetPlayers()

while true do

wait(6)

TeleportService:TeleportToPrivateServer(placeId, reservedServer, TheDudes)

end

Error: TeleportService:TeleportToPrivateServer must be passed an array of players

I’m kind of confused by this, I’ve tried this with multiple people in a server and still resulted in this error, anyone able to lend me a hand?

Thanks
-Revelted

1 Like

This is happening since it is sending an empty array to the server since it’s only getting the players when the game just opened.

Move the “local TheDudes = game.Players:GetPlayers()” part under “wait(6)” and it should work.

Also, make the code check if there are players to teleport every time before running the command.

local TeleportService = game:GetService("TeleportService")

local placeId = 2558455770

local reservedServer = TeleportService:ReserveServer(placeId)

while true do

wait(6)

local TheDudes = game.Players:GetPlayers()

if #TheDudes>0 then
TeleportService:TeleportToPrivateServer(placeId, reservedServer, TheDudes)
end
end
1 Like

Omg I just saw that… Thanks so much >.<

Another question:

(the repeat is just for testing purposes, it will be made a function later)

Ive got it to teleport select players, but I want to make it so they are all teleported to an entirely different server. This just teleports them to the game for some reason, how do I fix that >.<?

(I’m a somewhat new coder*)

1 Like

Move the line that states “local reservedServer = TeleportService:ReserveServer(placeId)” under the wait, so it generates a new one each time.