How to select parts in a model until theres none left to select

Hello! :slight_smile: I have a small question on how to select parts in a model until theres none left to select
This is needed for my story game where it needs to teleport you to a random seat

here is the script:

local AmountofPlayers = 12
local TS = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local placeId = "8681722652"
local leaveGuiEvent = game.ReplicatedStorage.LeaveGuiEvent
local TransitionEvent = game.ReplicatedStorage.TransitionEvent
local list = {}
local gui = script.Parent.GuiPart.SurfaceGui
local billboard = script.Parent.billboardPart.billboardGui
local timer
local teleporting = false
local spawnTeleport = script.Parent.spawn
local function updateGui()
	gui.Frame.players.Text = #list
	billboard.Frame.players.Text = #list
end

local function removeFromList(character)
	for i=1,#list do
		if list[i] == character.Name then
			table.remove(list,i)
			updateGui()
		end
	end
end

local function teleportPlayers()
	if #list > 0 then
		script.Parent.GuiPart.SurfaceGui.Frame.Status.Text = "TELEPORTING"
		local playersToTeleport = {}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
				TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		local code = TS:ReserveServer(placeId)
		teleporting = true
		TS:TeleportToPrivateServer(placeId,code,playersToTeleport)
		repeat wait() until #list <= 0
		script.Parent.GuiPart.SurfaceGui.Frame.Status.Text = "READY"
		script.Parent.GuiPart.SurfaceGui.Frame.Status.TextColor3 = Color3.new(34/255,255/255,20/255)
		teleporting = false
	end
end

script.Parent.Gate.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		if teleporting == false then
			local char = hit.Parent
			local player = game.Players:FindFirstChild(char.Name)
			local alreadyExists = false

			for i=1,#list do
				if list[i] == char.Name then
					alreadyExists = true
				end
			end

			if alreadyExists == false then
				if #list < AmountofPlayers then
					table.insert(list,char.Name)
					char.PrimaryPart.CFrame = spawnTeleport.CFrame
					updateGui()
					leaveGuiEvent:FireClient(player)
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end

		end
	end
end)

leaveGuiEvent.OnServerEvent:Connect(function(player)
	if player.Character then
		player.Character.HumanoidRootPart.Anchored = false
		wait()
		player.Character.Humanoid.Jump = false
		wait()
		player.Character:MoveTo(game.Workspace.leaveRoomPart.Position)
		removeFromList(player.Character)
	end
end)

while wait() do
	timer = 30
	for i=1,timer do
		timer = timer - 1
		gui.Frame.time.Text = timer
		billboard.Frame.time.Text = timer
		wait(1)
	end
	teleportPlayers()
end

Thanks For Reading

From what you’re trying to do is to place players into seats and teleport them to ones with no one in it you could do a for loop to loop through every seat and check if there is an occupant in said seat.

for _, seat in pairs(worksapce.Seats:GetChildren()) do
      if not seat.Occupant then
            seat:Sit(player.Character.Humanoid)
      end
end

This script is just an example

local players = game:GetService("Players")

local seatsFolder = workspace.Seats

local function movePlayersToSeats()
	for _, player in ipairs(players:GetPlayers()) do
		local character = player.Character
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			for _, seat in ipairs(seatsFolder:GetChildren()) do
				if seat:IsA("Seat") then
					if not seat.Occupant then
						seat:Sit(humanoid)
						break
					end
				end
			end
		end
	end
end

Here’s the functionality you’re looking for.

where would i add that to the script

It’s an example to take inspiration from, I was hoping you’d be able to identify that yourself.

ok . . . .
.
.
.
.
.
.
.
.
…
.
.
.
.
.
.ok
.