TeleportAsync doesnt teleport my group of players

can someone give me a reason and an answer why my teleport script never teleports player and no theres no teleport failed error or something it just doesnt teleport ive already attempted so many time

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local textlabel = game.Workspace:WaitForChild("Cylinder"):WaitForChild("BillboardGui"):WaitForChild("TextLabel")
local countdownlabel = textlabel.Parent.Parent:WaitForChild("BillboardGui2"):WaitForChild("CountdownLabel")

local cylinder = workspace:WaitForChild("Cylinder")

local number = 0
local touchedPlayers = {}
local PlayersInQueue = {}

local seconds = 60
local minute = 1

local countdownActive = false

local function countdown()
	countdownActive = true
	while seconds <= 60 do
		seconds -= 1
		if seconds < 0 then
			minute -= 1
			seconds = 59
		end
		countdownlabel.Text = string.format(tostring(minute) .. ":%02d", seconds)
		if countdownlabel.Text == "0:00" then
			break
		end
		task.wait(1)
	end
end

local function QueuePlayer()
	cylinder.Touched:Connect(function(hit)
		if not hit or not hit.Parent then return end

		local character = hit.Parent
		local player = Players:GetPlayerFromCharacter(character)

		if not player or not player:IsDescendantOf(Players) then return end -- Check if player is still connected

		if touchedPlayers[player] then
			return 
		end

		touchedPlayers[player] = true
		number += 1

		print(player.Name .. " touched for the first time")
		print("Current count:", number)
		textlabel.Text = tostring(number).."/".."30"

		table.insert(PlayersInQueue, player) -- Add player to queue after validation

		-- Validate players in queue before teleporting
		local validPlayers = {}
		for _, queuedPlayer in ipairs(PlayersInQueue) do
			if queuedPlayer:IsDescendantOf(Players) then
				table.insert(validPlayers, queuedPlayer)
			end
		end

		if seconds == 0 and minute == 0 then
			local success, result = pcall(function()
				return TeleportService:TeleportAsync(130019145223765, validPlayers)
			end)
			textlabel.Text = "0/30"
			countdownlabel.Text = "2:00"
			QueuePlayer()

			if not success then
				warn("Teleport failed:", result)
			end

			if not countdownActive then
				task.spawn(countdown)
			end
		end
	end)
end

QueuePlayer()

Your countdown never starts. You’re checking if time is 0 before the countdown even runs.

Start the countdown when you hit enough players, then teleport when it finishes. Also you’re creating a new Touched connection every teleport which stacks them up.

Not 100% sure this’ll work but try:

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local textlabel = game.Workspace:WaitForChild("Cylinder"):WaitForChild("BillboardGui"):WaitForChild("TextLabel")
local countdownlabel = textlabel.Parent.Parent:WaitForChild("BillboardGui2"):WaitForChild("CountdownLabel")
local cylinder = workspace:WaitForChild("Cylinder")

local number = 0
local touchedPlayers = {}
local PlayersInQueue = {}
local countdownActive = false

local function Countdown()
	countdownActive = true
	local seconds = 60
	local minute = 1
	
	while true do
		seconds -= 1
		if seconds < 0 then
			minute -= 1
			seconds = 59
		end
		countdownlabel.Text = string.format("%d:%02d", minute, seconds)
		
		if minute == 0 and seconds == 0 then
			break
		end
		task.wait(1)
	end
	
	local validPlayers = {}
	for _, queuedPlayer in ipairs(PlayersInQueue) do
		if queuedPlayer:IsDescendantOf(Players) then
			table.insert(validPlayers, queuedPlayer)
		end
	end
	
	local success, result = pcall(function()
		TeleportService:TeleportAsync(130019145223765, validPlayers)
	end)
	
	if not success then
		warn("Teleport failed:", result)
	end
	
	number = 0
	touchedPlayers = {}
	PlayersInQueue = {}
	textlabel.Text = "0/30"
	countdownlabel.Text = "2:00"
	countdownActive = false
end

cylinder.Touched:Connect(function(hit)
	if not hit or not hit.Parent then return end
	
	local character = hit.Parent
	local player = Players:GetPlayerFromCharacter(character)
	
	if not player or touchedPlayers[player] then return end
	
	touchedPlayers[player] = true
	number += 1
	table.insert(PlayersInQueue, player)
	
	textlabel.Text = tostring(number).."/30"
	
	if number >= 30 and not countdownActive then
		task.spawn(Countdown)
	end
end)

lmk if it works

1 Like

I was attempting to make my countdown run inside the queue function before and if the time is 0 i call the function again inside the function supposedly for me to make it repeat forever ok so heres the thing

1 Like

fixed the problem, countdown thread was running asynchronous

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.