Teleporting multiple players

Let’s say you have a table set up with 15 players in game.Players. You need to teleport all 15 of them to a second place within the game, but only those 15. How would you do this?

1 Like

Would you want this to like, teleport all those players to the same server? Or just teleport them to a different game instance.

There are multiple ways to do what you’re requesting. It does depend on what you want, however.

Same Server

The most practical way to do this would be to use TeleportPartyAsync, as this method guarantees to put all the players in the same server.

local tps = game:GetService("TeleportService")
tps:TeleportPartyAsync(id,arrayOfPlayers)

The other method to do so would be to loop through players and use the classic Teleport method. This is not guaranteed to put all the players in the same server.

local tps = game:GetService("TeleportService")
for i,v in pairs(arrayOfPlayers) do
    tps:Teleport(id,v)
    wait()
end

Different Servers

If you want everyone in their own server, you can reserve a server (using ReserveServer and TeleportToPrivateServer) for each player and teleport them to it.

local tps = game:GetService("TeleportService")
for i,v in pairs(arrayOfPlayers) do
    local code,privateServerId = tps:ReserveServer(id,v)
    tps:TeleportToPrivateServer(id,code,{v})
    wait()
end

(Or you can set the max player count to 1 and use the default teleport method, whatever works for you.)

17 Likes

Sorry for the bump, but I’m trying to use teleportpartyasync and it won’t work when there’s only one person in the game (necessary for my party system that allows you to play even when you’re alone in a party)

Nevermind, I just realized that using :GetPlayers() won’t work because it returns a table, not an array like :GetChildren does