In my game I allow players to teleport between places along with some data using teleport async. Recently allowed around 20-30 testers to test the game, and the teleport broke and threw an error. It states “Teleport failed because the previous one is in processing.”
The solution to this is supposed to use TeleportInitFailed, however this IS used in the teleportmodule so I dont understand how it can throw this error.
It got so bad people would be stuck for up to 5 mins befoe teleporting.
This is the script:
local TeleportService = game:GetService(“TeleportService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local TeleportModule = {}
local RETRY_DELAY = 2
local MAX_WAIT = 10
– Create remote event instance
local teleportEvent = Instance.new(“RemoteEvent”)
teleportEvent.Name = “TeleportEvent”
teleportEvent.Parent = ReplicatedStorage
function TeleportModule.teleportWithRetry(targetPlaceID, playersTable, teleportOptions)
local currentWait = 0
-- Show custom teleport screen to valid players if client event is connected
teleportEvent:FireAllClients(playersTable, true)
local function doTeleport(players, options)
if currentWait < MAX_WAIT then
local success, errorMessage = pcall(function()
return TeleportService:TeleportAsync(targetPlaceID, players, options)
end)
if not success then
warn(errorMessage)
-- Retry teleport after defined delay
wait(RETRY_DELAY)
currentWait = currentWait + RETRY_DELAY
doTeleport(players, teleportOptions)
end
else
-- On failure, hide custom teleport screen for remaining valid players
teleportEvent:FireAllClients(players, false)
return true
end
end
TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
if teleportResult ~= Enum.TeleportResult.Success then
warn(errorMessage)
-- Retry teleport after defined delay
wait(RETRY_DELAY)
currentWait = currentWait + RETRY_DELAY
doTeleport({player}, teleportOptions)
end
end)
-- Fire initial teleport
doTeleport(playersTable, teleportOptions)
end
return TeleportModule