Attempted to teleport error

Hello, I am having this issue in my game using a teleport method from the main game to a specific place connected to the game. I am getting the “attempted to teleport to a place” that is restricted error. I have tried enabling everything in the game settings security tab in both of the places, the issue still occurs. I will post the script we are using.

local TweenService = game:GetService("TweenService")
local TeleportService = game:GetService("TeleportService")

local safeTeleport = require(script:WaitForChild("SafeTeleport"))

local lobbies = workspace:WaitForChild("Lobbies")

for i, lobby in pairs(lobbies:GetChildren()) do
	local playersInLobby = {}
	
	local seats = lobby:WaitForChild("Van"):WaitForChild("Seats")
	local hitbox = lobby:WaitForChild("Join"):WaitForChild("Hitbox")
	local display = hitbox:WaitForChild("Display")
	
	local playerCount = display:WaitForChild("PlayerCount")
	local timer = display:WaitForChild("Timer")
	
	timer.Text = ""
	playerCount.Text = #playersInLobby .. "/" .. #seats:GetChildren() .. " Players"
	
	hitbox.Touched:Connect(function(otherPart)
		local char = otherPart.Parent
		local plr = Players:GetPlayerFromCharacter(char)
		
		if plr and not table.find(playersInLobby, plr) then
			local seat = seats:FindFirstChild(1 + #playersInLobby)
			local gui = plr.PlayerGui.MainGui
			
			table.insert(playersInLobby, plr)
			
			char.HumanoidRootPart.Anchored = true
			
			char.Humanoid.WalkSpeed = 0
			char.Humanoid.JumpPower = 0
			
			char.Humanoid.PlatformStand = true
			
			char.PrimaryPart.CFrame = seat.CFrame
			
			gui.ExitLobby.Visible = true
			
			playerCount.Text = #playersInLobby .. "/" .. #seats:GetChildren() .. " Players"
			
			local function onPlayerLeave()
				local pos = 0

				for i, newPlr in ipairs(playersInLobby) do
					if newPlr == plr then
						pos = i
					end
				end

				for i, newPlr in ipairs(playersInLobby) do
					if i > pos then
						local newSeat = seats:FindFirstChild(i - 1)

						newPlr.Character.PrimaryPart.CFrame = newSeat.CFrame
					end
				end

				table.remove(playersInLobby, pos)

				playerCount.Text = #playersInLobby .. "/" .. #seats:GetChildren() .. " Players"
			end
			
			plr:GetPropertyChangedSignal("Parent"):Connect(onPlayerLeave)
			
			gui.ExitLobby.MouseButton1Click:Connect(function()
				gui.ExitLobby.Visible = false
				gui.Timer.Visible = false
				
				char.PrimaryPart.Anchored = false
				char.Humanoid.JumpPower = 50
				char.Humanoid.WalkSpeed = 16

				char.Humanoid.PlatformStand = false
				
				plr.Character.HumanoidRootPart.CFrame = lobby:WaitForChild("Join"):WaitForChild("Exit").CFrame
				
				onPlayerLeave()
			end)
			
			if #playersInLobby == 1 then
				timer.Text = "5s"
				
				for i, newPlr in pairs(playersInLobby) do
					local gui = newPlr.PlayerGui.MainGui
					gui.Timer.Text = "5s"
					gui.Timer.Visible = true
				end

				for i = 1, 5 do
					task.wait(1)

					if #playersInLobby < 1 then
						timer.Text = ""
						break
					end
					
					for e, newPlr in pairs(playersInLobby) do
						local gui = newPlr.PlayerGui.MainGui
						gui.Timer.Text = 5 - i .. "s"
					end

					timer.Text = 5 - i .. "s"
				end
				
				for i, newPlr in ipairs(playersInLobby) do
					local gui = newPlr.PlayerGui.MainGui
					local seat = seats:GetChildren()[i]
					gui.ExitLobby.Visible = false
					gui.Timer.Visible = false
					
					local weld = Instance.new("WeldConstraint", seat)
					weld.Part0 = seat
					weld.Part1 = newPlr.Character.PrimaryPart
					newPlr.Character.Humanoid.WalkSpeed = 0
					newPlr.Character.Humanoid.JumpPower = 0
					newPlr.Character.PrimaryPart.Anchored = false
				end
				
				for i, part in pairs(lobby:WaitForChild("Van"):GetDescendants()) do
					if part ~= lobby.Van.PrimaryPart then
						if part:IsA("BasePart") then
							local weld = Instance.new("WeldConstraint", lobby.Van.PrimaryPart)
							weld.Part0 = lobby.Van.PrimaryPart
							weld.Part1 = part
							part.Anchored = false
						end
					end
				end
				
				TweenService:Create(lobby.Van.PrimaryPart, TweenInfo.new(2.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {CFrame = lobby.StopAcceleration.CFrame}):Play()
				
				delay(2.5, function()
					local server = TeleportService:ReserveServer(13933860205)
					local options = Instance.new("TeleportOptions")
					options.ReservedServerAccessCode = server
					
					for i, newPlr in pairs(playersInLobby) do
						local gui = newPlr.PlayerGui.MainGui
						gui.BlackScreen.BackgroundTransparency = 1
						gui.BlackScreen.Visible = true
						TweenService:Create(gui.BlackScreen, TweenInfo.new(6, Enum.EasingStyle.Linear), {BackgroundTransparency = 0}):Play()
						
						delay(6, function()
							safeTeleport(13937594482, {newPlr}, options)
						end)
					end
					
					TweenService:Create(lobby.Van.PrimaryPart, TweenInfo.new(7, Enum.EasingStyle.Linear), {CFrame = lobby.GoTo.CFrame}):Play()
				end)
			end
		end	
	end)
end```

Sorry this is the second part of the script inside of it as a new one.


local ATTEMPT_LIMIT = 5
local RETRY_DELAY = 1
local FLOOD_DELAY = 15

local function SafeTeleport(placeId, players, options)
	local attemptIndex = 0
	local success, result -- define pcall results outside of loop so results can be reported later on

	repeat
		success, result = pcall(function()
			return TeleportService:TeleportAsync(placeId, players, options) -- teleport the player in a protected call to prevent erroring
		end)
		attemptIndex += 1
		if not success then
			task.wait(RETRY_DELAY)
		end
	until success or attemptIndex == ATTEMPT_LIMIT -- stop trying to teleport if call was successful, or if retry limit has been reached

	if not success then
		warn(result) -- print the failure reason to output
	end

	return success, result
end

local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
	if teleportResult == Enum.TeleportResult.Flooded then
		task.wait(FLOOD_DELAY)
	elseif teleportResult == Enum.TeleportResult.Failure then
		task.wait(RETRY_DELAY)
	else
		-- if the teleport is invalid, don't retry, just report the error
		error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
	end

	SafeTeleport(targetPlaceId, {player}, teleportOptions)
end

TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)

return SafeTeleport```

Check if this video fixes your problem. If not, then the game you are teleporting to is actually restricted from public view and you should check again.

1 Like

it fixed on its own randomly. I guess the place had to get approved.

1 Like