My teleporting system wont let you join back a queue after leaving it

Hello again, i’m still making a teleporting system for a client and i noticed that the player after leaving a queue couldn’t join back the same one. How can i fix this?

-- 
placeId = 5551067564 --Replace with your the game you want to be teleported to

local TeleportSerivce = game:GetService("TeleportService")
local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local leaveEvent = ReplicatedStorage.RemoteEvents.LeaveEvent
local joinEvent = ReplicatedStorage.RemoteEvents.JoinEvent
local triggerPart = script.Parent
local teleportNode = script.Parent.Parent:WaitForChild("TeleportNode") -- The part that the players are teleported to
local teleportNode2 = script.Parent.Parent:WaitForChild("TeleportNode2") -- The part that gets the player out
local Folder = triggerPart:WaitForChild("Players")
local timer = script.Parent.Parent.billboardpart.SurfaceGui:WaitForChild("Timer")
local timerTime = 45
local playerCount =script.Parent.Parent.billboardpart.SurfaceGui:WaitForChild("PlayerCount")
local maxPlayers = 2 --This is the max ammount of players
local countDownDebounce = true
local debouncer = false

function checkIfExist(Character)
	for _, value in pairs(Folder:GetChildren()) do
		if value.Value == Character then
			return true
		end
	end
	return false
end

function teleportParty()
	local Plrs = {}
	for _, value in pairs(Folder:GetChildren()) do
		if value.Value then
			table.insert(Plrs, Players:GetPlayerFromCharacter(value.Value))
		end
	end
	local ReserveCode = TeleportSerivce:ReserveServer(placeId)
	TeleportSerivce:TeleportToPrivateServer(placeId, ReserveCode, Plrs) --Teleports the players in the teleporters
	Folder:ClearAllChildren()
end

function countdown()
		for i = 1, 45, 1 do
			wait(1)
			timer.Text = timerTime - i

			if timer.Text == "0" then
				teleportParty()
				print("Teleporting")
				wait(5)
				countdown()
				break
			end
		end
end

function updateGUI()
	playerCount.Text = tostring(#Folder:GetChildren()).."/"..tostring(maxPlayers)
	if #Folder:GetChildren() >= maxPlayers or timer.Text == "0" then
		teleportParty()
	end
end

Players.PlayerAdded:Connect(function()
	triggerPart.Touched:Connect(function(hit)
		if not debouncer and  #Folder:GetChildren() < maxPlayers  then
			debouncer = true
			if hit.Parent:FindFirstChild("Humanoid") and #Folder:GetChildren() < maxPlayers then
				print("Player is touching game teleporter")
				if not checkIfExist(hit.Parent) then
					local Tag = Instance.new("ObjectValue")
					Tag.Value = hit.Parent
					Tag.Parent = Folder
					hit.Parent:SetPrimaryPartCFrame(teleportNode.CFrame)
					joinEvent:FireClient(Players:GetPlayerFromCharacter(hit.Parent))
					if #Folder:GetChildren() <= maxPlayers then
						print("Starting countdown")
						countdown()
						debouncer = true
					end
				end
			end
			debouncer = false
		end
	end)
end)

leaveEvent.OnServerEvent:Connect(function(player)
	for _, value in pairs(Folder:GetChildren()) do
		if value.Value == player.Character then
			value.Value:Destroy()
			player.Character:SetPrimaryPartCFrame(teleportNode2.CFrame)
		end
	end
end)

Folder.ChildAdded:Connect(updateGUI)
Folder.ChildRemoved:Connect(updateGUI)

You’re destroying the “value.Value” which would be the character and not the value inside the folder. So instead of destroying the character you want to destroy the actual value instance inside the folder. I’m assuming once they leave it checks if they already exist, and it sees that they do exist.

if value.Value == player.Character then
			value.Value:Destroy()
			player.Character:SetPrimaryPartCFrame(teleportNode2.CFrame)
		end

instead

if value.Value == player.Character then
			value:Destroy()
			player.Character:SetPrimaryPartCFrame(teleportNode2.CFrame)
		end

I’m not 100% sure, but I think your countdown() goes endless once triggered. So it goes into countdown() but then later again into countdown() forever. This will halt the exeuction and never reach debouncer = false because it will wait for “countdown()” forever. You use a fixed value timerTime that never changes (which is not the problem here). Then the countdown() counts down from timerTime to 0 and once it reaches 0 again goes into countdown() and the whole thing starts again. I am not sure why you have countdown() in itself. But not only that, your countdown counts wrong because it decreases by i every loop instead of one, but i always increases by 1 in the loop. So instead of 45-1-1-1-1-... you have 45-1-2-3-4-5-6-7-8-9 which just by coincidence results to at the end be 0 :smiley: and will result in countdown() being called again. If you had a number other than 45 you would have seen this earlier as then the text would act weird (go into negative and never reach zero), but by using 45 it ends up exactly at zero. So remove the countdown() in countdown() and change timer.Text = timerTime - i in it to timer.Text = tonumber(timer.Text) - 1. I hope that helps, sorry if not.

// EDIT: I think timer.Text = timerTime - i seems ok, though a bit irritating. But it will still go into countdown() forever because once it goes into if timer.Text == "0" then it goes into countdown(), then into for i = 1, 45, 1 do and then again adjust timer.Text = timerTime - i, setting it to 45-1, resetting the whole cycle. So the endless countdown()calling may be your problem.