Answered by
5 years ago Edited 5 years ago
The Occupant
property of VehicleSeat
correlates to the Humanoid
, not the Player
. Since TeleportService’s method TeleportToPrivateServer
requires an array of Players, we have to reformat the table to contain the affiliated Players to the Occupant Humanoids.
This doesn’t take us off rails too far, as we can take the knowledge of the Humanoid
being a child of Character
, and go from there using Players’ GetPlayerFromCharacter
method.
Create a function that will iterate through our Vehicle, and return us a table of all Seated Players with the information we just learned:
01 | local TeleportService = game:GetService( "TeleportService" ) |
02 | local Reserve = TeleportService:ReserveServer(game.PlaceId) |
04 | local Players = game:GetService( "Players" ) |
06 | local Car = workspace.Car 1 |
08 | local function SeatedPlayersThreshold(Vehicle, PotentialMinimum) |
09 | local AllSeats = { } do |
10 | for Seat,_ in pairs (Vehicle:GetDescendants()) do |
11 | if (Vehicle [ Seat ] :IsA( "VehicleSeat" )) then |
16 | if not (#AllSeats > = (PotentialMinimum and PotentialMinimum or 1 ) then return end |
17 | return PotentialMinimum or #AllSeats |
20 | local function GetSeatedPlayersFrom(Vehicle) |
21 | if not (Vehicle) then return end |
22 | local SeatedPlayers = { } |
23 | for _,Seat in pairs (Vehicle:GetDescendants()) do |
24 | if (Seat:IsA( "VehicleSeat" )) then |
25 | local PlayerInSeat = Players:GetPlayerFromCharacter(Seat.Occupant.Parent) |
26 | if (Players [ PlayerInSeat ] ) then |
27 | table.insert(SeatedPlayers, PlayerInSeat) |
31 | if (#SeatedPlayers < SeatedPlayersThreshold(Vehicle)) then return end |
35 | TeleportService:TeleportToPrivateServer(game.PlaceId, Reserve, GetSeatedPlayersFrom(Car)) |
Remember to accept this answer if it helps!