Help with teleport system

I’m making a player limiter timer teleport system

how could I implement that when you touch a teleporter and then you go touch another teleporter
it deletes you from the first ones list

--			SERVICES			--

local Players = game:GetService('Players')
local ts = game:GetService('TeleportService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--			 REMOTES			--

local remote1 = ReplicatedStorage:WaitForChild('Remotes'):WaitForChild('JoinLobby')
local remote2 = ReplicatedStorage:WaitForChild('Remotes'):WaitForChild('LeaveLobby')

--			GAME INFO			--
local PlaceId = 9479160887
local maxPlayers = 16

--		PLAYERS AND NODES		--
local Folder = script.Parent:WaitForChild('Players')
local node = script.Parent.Parent:WaitForChild('TeleportNode')
local node2 = script.Parent.Parent:WaitForChild('TeleportNode2')

--			UI STUFF			--

local playerCount = script.Parent:WaitForChild('billboard'):WaitForChild('SurfaceGui'):WaitForChild('TextLabel')
local timerText = script.Parent:WaitForChild('billboard'):WaitForChild('timer'):WaitForChild('TextLabel')
local intermissionLength = 30

local TimerActive = false

--        OTHER TELEPORTERS    --

local teleporter2 = script.Parent.Parent:WaitForChild('teleporter2')
local teleporter3 = script.Parent.Parent:WaitForChild('teleporter3')
local Folder2 = teleporter2:WaitForChild('Players')
local Folder3 = teleporter3:WaitForChild('Players')


--			FUNCTIONS			--

function checkIfExists(Character) -- checks if player exists
	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 not value then continue end
		table.insert(Plrs,Players:GetPlayerFromCharacter(value.Value))
	end
	local Code = ts:ReserveServer(PlaceId)
	ts:TeleportToPrivateServer(PlaceId,Code,Plrs)
	Folder:ClearAllChildren()	
end

function timer()
	if TimerActive then return end

	TimerActive = true
	intermissionLength = 30

	while task.wait() do
		for i = intermissionLength,0,-1 do
			timerText.Visible = true
			wait(1)
			intermissionLength =  i
			timerText.Text = i
			if #Folder:GetChildren() == 0   then
				intermissionLength = 30
				TimerActive = false
				return
			end
		end
		if #Folder:GetChildren() >= maxPlayers or intermissionLength == 0 then
			TimerActive = false
			teleportParty()				
		end
	end
end


function UpdateGui()
	playerCount.Text = tostring(#Folder:GetChildren())..'/'..tostring(maxPlayers)
end


script.Parent.Touched:Connect(function(part)
	if not part.Parent:FindFirstChild('Humanoid') then return end

	local player = part.Parent
	if not checkIfExists(player) then
		local Tag = Instance.new('ObjectValue')
		Tag.Value = player
		Tag.Parent = Folder
		part.Parent:SetPrimaryPartCFrame(node.CFrame)
		remote1:FireClient(Players:GetPlayerFromCharacter(part.Parent))
	end
	if #Folder:GetChildren() > 0 then
		timer()
	end
end)

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

end)

Folder.ChildAdded:Connect(UpdateGui)
Folder.ChildRemoved:Connect(UpdateGui)```
1 Like