Lobby Teleports system not working

I created this game with the usual hobby where you can enter the various cells for 1,2,3 players max and teleport to another place. The problem is that when I try to teleport this roblox message appears:

This is the code:

local TS = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local placeId = "17854752923" -- Enter a second Id Place.
local leaveGuiEvent = game.ReplicatedStorage.LeaveGuiEvent
local TransitionEvent = game.ReplicatedStorage.TransitionEvent
local list = {}
local billboard = script.Parent.billboardPart.billboardGui
local timer
local teleporting = false
local spawnTeleport = script.Parent.spawn

local function updateGui()
	billboard.Frame.players.Text = "Players: " ..#list.. "/1" -- Change the number 16 according to the Max Player who want to be teleported.
end

local function removeFromList(character)
	for i=1,#list do
		if list[i] == character.Name then
			table.remove(list,i)
			updateGui()
		end
	end
end

local function teleportPlayers()
	if #list > 0 then
		billboard.Frame.Status.Text = "TELEPORTING"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		local playersToTeleport = {}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
				TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		local code = TS:ReserveServer(placeId)
		teleporting = true
		TS:TeleportToPrivateServer(placeId,code,playersToTeleport)
		repeat wait() until #list <= 0
		billboard.Frame.Status.Text = "READY"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		teleporting = false
	end
end

script.Parent.Gate.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		if teleporting == false then
			local char = hit.Parent
			local player = game.Players:FindFirstChild(char.Name)
			local alreadyExists = false
			
			for i=1,#list do
				if list[i] == char.Name then
					alreadyExists = true
				end
			end
			
			if alreadyExists == false then
				if #list < 1 then -- Many Players have been teleported.
					table.insert(list,char.Name)
					char.PrimaryPart.CFrame = spawnTeleport.CFrame
					updateGui()
					leaveGuiEvent:FireClient(player)
				end
				
				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end
			
		end
	end
end)

leaveGuiEvent.OnServerEvent:Connect(function(player)
	if player.Character then
		player.Character.HumanoidRootPart.Anchored = false
		wait()
		player.Character.Humanoid.Jump = true
		wait()
		player.Character:MoveTo(game.Workspace.leaveRoomPart.Position)
		removeFromList(player.Character)
	end
end)

while wait() do
	timer = 15 -- Wait time before teleport change to whawtever you want it to be
	for i=1,timer do
		timer = timer - 1
		billboard.Frame.time.Text = timer
		wait(1)
	end
	teleportPlayers()
end

Pls help me, TY.
FROG3R.

did you not check using this:
image

your error should be about trying to teleport an array.
your line “TS:TeleportToPrivateServer(placeId,code,playersToTeleport)” wants you to input an instance (the player)

for ind , PlayerToTp in pairs(playersToTeleport) do
	TS:TeleportToPrivateServer(placeId,code,PlayerToTp)
end

try the replacement code and let me know if theres any issues

You have to make sure that the place you’re trying to teleport players to is public.
Otherwise, teleporting players there won’t work.

Thank you very much, I changed the code and now it works.

1 Like

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