Hey, I’ve recently started a story game and for the teleport feature where it teleports all the players sitting in on several seats, but I am unsure how to gather the players’ names then teleporting them, could anybody help me, please?
local SeatFolder = workspace.SeatFolder:GetChildren()
local TeleportService = game:GetService("TeleportService")
for _, Seat in pairs(SeatFolder) do
if Seat.Occupant then
local Char = Seat.Occupant.Parent
local Player = game.Players:GetPlayerFromCharacter(Char)
if Player then
local PlayerName = Player.Name
TeleportService:Teleport(PlaceId, Player)
end
end
end
Also would that be a serverscript?
Its by me same. I want this it work
You’re meant to put all the Seats you want to correspond to the teleporting in the Folder, not the script. Put the script in like, Workspace or ServerScriptService
Before anything, do you already a sort of “truck” thing where the seats are set up? You can make it so when it’s time to teleport a group of players, it goes through the seats in the truck, and checks if they have an Occupant, and if they do, get the Parent of the occupant and use that to get the Player, and add the Player to a table to then use for TeleportAsync
An example would be this
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = --Your place id
local truck = --Thing with a lot of seats
--When it's time to teleport
local playersTable = {}
--Ideally you have the seats in a folder, so the example will be that
--This assumes the thing you gave has a folder/container called Seats
for _,seat in pairs(truck.Seats:GetChildren()) do
local occupant = seat.Occupant
local player = occupant and Players:GetPlayerFromCharacter(occupant.Parent)
if not player then
continue
end
table.insert(playersTable,player)
end
--Now we'll assume you want it reserved, so we can set up some Teleport options
local options = Instance.new("TeleportOptions")
options.ShouldReserveServer = true
TeleportService:TeleportAsync(PLACE_ID, playersTable, options)
It provides everything that is needed for teleportation. When it’s time to teleport, you just do a system similar to what I did, get the players sitting via Seat.Occupant
and get the parent of it and use GetPlayerFromCharacter
, and then send them to a ReservedServer
TeleportAsync
mentions a bit more information about the function