Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Teleport a group of players in an elevator?

Hello everyone!

I am attempting to create an elevator that teleports a specific group of players, like in the game Tower Defense Simulator or most story games. However, I am having a bit of trouble.

Here, I am trying to select only the players that I want. When tested, it prints the correct player names and gives no errors. I think it is functioning exactly how I want it to.

local readyPlayers = {}
local plrs = game.Players:GetChildren()

for i = 1, #plrs do
	if plrs[i].Ready.Value == 1 then
		table.insert(readyPlayers,1,plrs[i].Name)
	end
end

Here is the actual teleport script:

local service = game:GetService("TeleportService")
local server = service:ReserveServer(12345678)
service:TeleportToPrivateServer(12345678,server,plrs)

When this is ran, it gives the error "Unable to cast value to object." If I change the line to below, it works, but I want it to only be certain players and not everyone.

local players = game.Players:GetChildren()
service:TeleportToPrivateServer(12345678,server,players)

Does anyone know how to fix the error? Thank you for reading through all of this :)

2 answers

You can't run this on multiple players, just one.

do this instead:

local server = service:ReserveServer(12345678)

for _,plr in pairs(game.Players:GetPlayers()) do
	service:TeleportToPrivateServer(idHere,server,plr)
end

You actually can teleport multiple players to the same server:

local Players = game:GetService("Players") -- change to the specified players
local TeleportService = game:GetService("TeleportService")
 
local placeId = 0 -- replace
local playerList = Players:GetPlayers()
 
local success, result = pcall(function()
    return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
 
if success then
    local jobId = result
    print("Players teleported to "..jobId)
else
    warn(result)
end

Here is the API reference Link (URL): developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportPartyAsync

This discussion is preserved as it was. New answers, comments, and votes are closed.