Not teleporting to reserve server [REPOST]

I am making a lobby system, but when the countdown ends, it doesn’t teleport me. I tried printing the players table as shown in the code:

local tp = game:GetService("TeleportService")


local players = {}



local function lobby()
	for i = 15, 0, -1 do
		script.Parent.BillboardAttach.BillboardGui.Countdown.Text = tostring(i)
		script.Parent.BillboardAttach.BillboardGui.PlayerSlot.Text = tostring(#players).."/1"
		script.Parent.Touched:Connect(function(hit)
			if game.Players:GetPlayerFromCharacter(hit.Parent) then
				--check if the player has already joined this lobby queue
				if table.find(players, game.Players:GetPlayerFromCharacter(hit.Parent), 1) then
					--if the player is already in the lobby, do nothing
					return
				else
					--else, add them to queue for a game
					table.insert(players, game.Players:GetPlayerFromCharacter(hit.Parent))
				end
			end
		end)

		script.Parent.TouchEnded:Connect(function(hit)
			--remove the player from the list
			if game.Players:GetPlayerFromCharacter(hit.Parent) then
				if table.find(players, game.Players:GetPlayerFromCharacter(hit.Parent), 1) then
					table.remove(players, table.find(players, game.Players:GetPlayerFromCharacter(hit.Parent), 1))
				else
					return
				end
			end
		end)
		task.wait(1)
	end
	if #players >= 1 then
		
		local success, errorMessage = pcall(function()
			local tpSlot = tp:ReserveServer(2946271611)
			tp:TeleportToPrivateServer(2946271611, tpSlot, players)
			print(players)
		end)

		table.clear(players)
	end
end

while true do
	lobby()
end

No errors appear on the console. Neither does the printing.

I had to repost this just so that i can simply get an answer.

1 Like

Add print statements and see what it does.

There’s a print statement in the pcall

ADD more please. One is not enough, add a print statement for every step, and see when it returns nil or just nothing.

I added some more print statements, here is the code:

local tp = game:GetService("TeleportService")


local players = {}



local function lobby()
	for i = 15, 0, -1 do
		script.Parent.BillboardAttach.BillboardGui.Countdown.Text = tostring(i)
		script.Parent.BillboardAttach.BillboardGui.PlayerSlot.Text = tostring(#players).."/1"
		script.Parent.Touched:Connect(function(hit)
			if game.Players:GetPlayerFromCharacter(hit.Parent) then
				--check if the player has already joined this lobby queue
				if table.find(players, game.Players:GetPlayerFromCharacter(hit.Parent), 1) then
					--if the player is already in the lobby, do nothing
					return
				else
					--else, add them to queue for a game
					table.insert(players, game.Players:GetPlayerFromCharacter(hit.Parent))
					print("added player")
				end
			end
		end)

		script.Parent.TouchEnded:Connect(function(hit)
			--remove the player from the list
			if game.Players:GetPlayerFromCharacter(hit.Parent) then
				if table.find(players, game.Players:GetPlayerFromCharacter(hit.Parent), 1) then
					table.remove(players, table.find(players, game.Players:GetPlayerFromCharacter(hit.Parent), 1))
					print("removed player")
				else
					return
				end
			end
		end)
		task.wait(1)
	end
	if #players >= 1 then
		print("enough for game to start")
		local success, errorMessage = pcall(function()
			print("making tp code...")
			local tpSlot = tp:ReserveServer(2946271611)
			tp:TeleportToPrivateServer(2946271611, tpSlot, players)
			print(players)
		end)
		
		print("players cleared")
		table.clear(players)
	end
end

while true do
	lobby()
end


as of the console, the player removing and adding works just as fine. it creates the reserve code thing, but doesn’t teleport the players.

Before

if #players >= 1 then

Add a print that prints the players.

it prints the players before the statement, but smh in the pcall it doesn’t

Can you show the output of all the prints.

ok
image
image

It looks like the issue may be related to the fact that you’re checking the size of the players table right after initiating the countdown loop, which means the teleportation happens immediately after starting the countdown without giving players a chance to join. Additionally, you are using a while true loop, which can cause performance issues and may not be the best approach for handling a lobby system.

local tp = game:GetService("TeleportService")

local players = {}
local countdownDuration = 15 -- Set the countdown duration in seconds

local function updateBillboard()
    script.Parent.BillboardAttach.BillboardGui.Countdown.Text = tostring(countdownDuration)
    script.Parent.BillboardAttach.BillboardGui.PlayerSlot.Text = tostring(#players).."/1"
end

local function lobby()
    for i = countdownDuration, 1, -1 do
        updateBillboard()
        wait(1)
    end

    updateBillboard() -- Ensure the final countdown state is displayed

    if #players >= 1 then
        local success, errorMessage = pcall(function()
            local tpSlot = tp:ReserveServer(2946271611)
            tp:TeleportToPrivateServer(2946271611, tpSlot, players)
            print(players)
        end)

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

        table.clear(players)
    end
end

script.Parent.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not table.find(players, player, 1) then
            table.insert(players, player)
            updateBillboard()
        end
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local index = table.find(players, player, 1)
        if index then
            table.remove(players, index)
            updateBillboard()
        end
    end
end)

while true do
    lobby()
    wait(1)
end
1 Like

for some reason the countdown froze

It seems like the issue might be related to the while true loop in your code. When you have a continuous loop running without any breaks, it can cause the game to freeze.

there is a wait() in the while loop and for some reason it still froze lol

also it’s not the game that froze, it’s the countdown, it doesn’t animate it counting down

local tp = game:GetService("TeleportService")

local players = {}
local countdownDuration = 15
local countdownEvent = Instance.new("BindableEvent")
local countdownRunning = false

local function updateBillboard()
    script.Parent.BillboardAttach.BillboardGui.Countdown.Text = tostring(countdownDuration)
    script.Parent.BillboardAttach.BillboardGui.PlayerSlot.Text = tostring(#players).."/1"
end

local function startCountdown()
    countdownRunning = true
    for i = countdownDuration, 1, -1 do
        updateBillboard()
        wait(1)
    end
    countdownEvent:Fire()
    countdownRunning = false
end

local function lobby()
    if #players >= 1 then
        local success, errorMessage = pcall(function()
            local tpSlot = tp:ReserveServer(2946271611)
            tp:TeleportToPrivateServer(2946271611, tpSlot, players)
            print(players)
        end)

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

        table.clear(players)
    end
end

script.Parent.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not table.find(players, player, 1) then
            table.insert(players, player)
            updateBillboard()
        end
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local index = table.find(players, player, 1)
        if index then
            table.remove(players, index)
            updateBillboard()
        end
    end
end)

countdownEvent.Event:Connect(lobby)

script.Parent.Touched:Connect(function(hit)
    if countdownRunning then
        return
    end
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        startCountdown()
    end
end)

now that the countdown works, i get Http Error 400 when in the actual roblox client

Try and debug the error in your game.

local success, errorMessage = pcall(function()
local tpSlot = tp:ReserveServer(2946271611)
tp:TeleportToPrivateServer(2946271611, tpSlot, players)
print(players)
end)

if not success then
warn(“Teleport failed:”, errorMessage)
end

I am not so sure but I think :ReserveServer() can only be called for the same game placeId or a place inside the actual experience only could that be your issue?

Then add a print statement between reserving the server and teleporting.