Need help figuring out how to figure out how to do a queue system

I need help how to make this work.

I dont know how i would make the timer reset when the player count goes under the amount needed
for the queue to start and how when a player joins the queue when there is already more than amount needed how to make the timer not glitch out.

Heres the current script

local function playerRemoved(player)
	
	board:FindFirstChild("SurfaceGui"):FindFirstChild("MainFrame"):FindFirstChild("Frame"):FindFirstChild(player.Name):Destroy()
	player.Character.Parent = game.Workspace
end


local function startTimer()
	local timer = board:FindFirstChild("SurfaceGui"):FindFirstChild("MainFrame"):FindFirstChild("CountDown")
	
	if timerOn == true then
		print("timer already on")
	else
		print("doing this")
		for i = 10, 0, -1 do
			timer.Text = i
			wait(1)
		end
	end
end











zon.playerEntered:Connect(function(player)
	
	playerAdded(player)
	
	local currAmount = #game.Workspace.InQueue:GetChildren()
	
	if currAmount >= 5 then
		startTimer()
		timerOn = true
		
	else
		timerOn = false
		print(5-currAmount.." players still needed")
	end
	
	
end)

zon.playerExited:Connect(function(player)
	
	playerRemoved(player)
	local currAmount = #game.Workspace.InQueue:GetChildren()
	if currAmount <= 5 then
		timerOn = false
	end
end)