Code only puts one player in table and teleports one?

trying to make like one of them story type games, and I’m having trouble w the teleportation from the lobby to the server.

local WaitTimePod1 = game.ReplicatedStorage.WaitTimePod1

local RegionPod1 = workspace.Pod1:WaitForChild("RegionPod1")

local TeleportService = game:GetService("TeleportService")

local Found = false

local maxWait = 30

local playerTable = {}

game.Players.PlayerAdded:Connect(function(player)
	print('code runs again')
	while wait() do
		
		if WaitTimePod1.Value > 0 then
			wait(1)
			WaitTimePod1.Value = WaitTimePod1.Value - 1
			if WaitTimePod1.Value == 0 then
				
				local region = Region3.new(RegionPod1.Position - (RegionPod1.Size/2), RegionPod1.Position + (RegionPod1.Size/2))
				local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, player.Character:GetDescendants())
				
				if #parts == 0 then
					WaitTimePod1.Value = maxWait
				end
								
				for _, part in pairs (parts) do
					if part:FindFirstAncestor(player.Name) then
						table.insert(playerTable, player)
						Found = true
						break
					else
						WaitTimePod1.Value = maxWait
						Found = false
					end
				end
				
				if Found == true then
					WaitTimePod1.Value = maxWait
					TeleportService:TeleportPartyAsync(5088845478, playerTable)
					game.Workspace.Pod1.PopupGui.PlayerAmtGui.TextLabel.Text = 'Teleporting...'
					wait(5)
				end
			end
		end
	end
end)
1 Like

The issue is that you break the loop indexing parts in the region once it finds only the player who entered. It sets found to true and then proceeds with the teleport event. If you are intending to teleport multiple players, you cannot break the loop after only finding a single player.

for _, part in pairs (parts) do
					if part:FindFirstAncestor(player.Name) then
						table.insert(playerTable, player)
						Found = true
						break -- You break only after finding one player and then proceed to teleport.... oh no!
					else
						WaitTimePod1.Value = maxWait
						Found = false
					end
				end
				
				if Found == true then
					WaitTimePod1.Value = maxWait
					TeleportService:TeleportPartyAsync(5088845478, playerTable)
					game.Workspace.Pod1.PopupGui.PlayerAmtGui.TextLabel.Text = 'Teleporting...'
					wait(5)
				end
			end