How to keep the queue system I'm making from getting frozen during teleporting?

I followed a tutorial on how to make a queue system, and it does queue up players like its supposed to and it also does teleport them. But theres a strange bug where after the players teleport its stuck saying “Teleporting…” and you cant enter the queue again.

I’ve tried debugging it with print and it doesn’t print anything starting at the teleportPlayers function, which is strange because it does teleport the players.

local TeleportService = game:GetService("TeleportService") --gets teleport service
local leaveButtonEvent = game.ReplicatedStorage.LeaveButton --gets leavebutton
local billboard= script.Parent.Overhead.BillBoardGui --gets billboard
local queue = {} --the queue of players
teleporting = false --debounce

--Things to configurate
local placeId = 18134798626 --id of game
local maxplayers = 4 --amount of players
local title = "Game" -- title

wait()
billboard.Frame.PlayerCount.Text = title.." ("..#queue.."/"..maxplayers..")" -- changes playercount label
script.Parent.Overhead.ProximityPrompt.ObjectText = title -- changes proximity prompt objecttitle



local function updatePlayerCount () --update player count
	billboard.Frame.PlayerCount.Text = title.."("..#queue.."/"..maxplayers..")" --playercount updating
end

script.Parent.Overhead.ProximityPrompt.Triggered:Connect(function(plr) --players presses proximity prompt

	--plr.Character.HumanoidRootPart.Position = script.Parent.TeleportPoint.Position

	if plr.Character then --checks if player
		if teleporting == false then -- checks if teleporting is false
			local char = plr.Character -- sets plr.character to char
			local duplicate = false -- so players cant go in twice
			
			for i=1, #queue do -- adds player to queue as i
				if queue[i] == char.Name then -- checks if i is equal to the character name
					duplicate = true -- allows player to enter (still cant duplicate)
				end
			end
			
					if duplicate == false then -- checks if duplicate is false
						if #queue < maxplayers then --checks if amount in queue is less than maxplayers
					plr.Character.HumanoidRootPart.Position = script.Parent.TeleportPoint.Position
							table.insert(queue, char.Name) -- inserts queue character name
							leaveButtonEvent:FireClient(plr) --fires client
							updatePlayerCount() --updates player count
					
						end
			
						
						plr.CharacterRemoving:Connect(function(char) -- checks if player left or reset
					if plr.Character then -- checks if its a character
						for i = 1, #queue do -- i is equal to one player and queue then
							if queue[i] == char.Name then --checks if player (queue[i]) is equal to char.name
								table.remove(queue, i) --removes player
								updatePlayerCount() --updates player count
							end
						end
					end
						
				end)
			end
		end
	end
end)

leaveButtonEvent.OnServerEvent:Connect(function(plr) --if player presses leave queue
	plr.Character.HumanoidRootPart.Position = script.Parent.LeavePoint.Position -- teleports player out of queue
	if plr.Character then --checks if character
		for i = 1, #queue do -- i is equal to one player and queue then
			if queue[i] == plr.Character.Name then -- if player is equal to character.name then
				table.remove(queue, i) -- remove player
				updatePlayerCount() --update player count
			end
		end
	end
end)






local function teleportPlayers () --teleport player function
	
	if #queue > 0 then --if queue is more than 0
		billboard.Frame.Time.Script.Disabled = false --disables script in time from the billboard
		local players = {} --amount of players
		
		for i=1, #queue do --i is equal to 1 player amount in queue then
			if game.Players:FindFirstChild(queue[i]) then --checks if player is in the queue
				table.insert(players, game.Players:FindFirstChild(queue[i])) --inserts player into queue
			else
				table.remove(queue, i) --if not in queue then remove queue
			end
		end
		local server = TeleportService:ReserveServer(placeId) --reserves server
		teleporting = true --teleporting set to true
		TeleportService:TeleportToPrivateServer(placeId, server, players) --teleports to private server
		repeat wait() until #queue <= 0 --waits until queue is less or equal to 0
		print("AllPlayersLeft")
		billboard.Frame.Time.Script.Disabled = true --disables script
		billboard.Frame.Time.Text = "" --sets text to nothing
		billboard.Frame.Time.TextColor3 = Color3.new(1,0,0) --changes color
	teleporting = false --teleporting set to false 
	
	end
	end

while wait() do --while loop wait do

	seconds = 25 --amount of intermission time
	for i=1, seconds do --for player and seconds do
		seconds = seconds - 1 --seconds - 1 second
		if billboard.Frame.Time.Script.Disabled == true then --script disabled then
			billboard.Frame.Time.Text = "Teleporting in "..seconds.." seconds" --amount until teleport
			
		end
		wait(1) --wait
	end
	teleportPlayers() --teleports players using the teleport player function
	
end


				

(also ignore the notes, I was just trying to see how the code worked, and I’m probably wrong in some areas lol)
What’s wrong with the code?