I’ve been using the SafeTeleport function found somewhere on Devforum in my last couple projects. Never had any issues. Today I went to try and code up some sort of Lobby → Game data transfer using the TeleportAsync result (which I’ve done in the past with no issues), but I can’t seem to get any result for the life of me. According to the API, it should be returning a TeleportAsyncResult. This will successfully teleport the player to the other game, but I can’t get any sort of result.
local function SafeTeleport(placeId: number, players: { Player }, options: TeleportOptions?) : (boolean, any?)
if RunService:IsStudio() then
return false, warn("Cannot teleport in studio...")
end
local attemptIndex = 0
local success, result -- define pcall results outside of loop so results can be reported later on
repeat
print("Trying to teleport players...")
success = pcall(function()
result = TeleportService:TeleportAsync(placeId, players, options) -- teleport the user in a protected call to prevent erroring
print(result)
end)
print(success, result)
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
print("Returning: ", success, result)
return success, result
end
That’s what I’m doing. If it was in studio, the teleport should error, and it should return no result either way. It should also catch my condition at the top of the function and actively warn me.
success, result = pcall(function()
return TeleportService:TeleportAsync(placeId, players, options) -- teleport the user in a protected call to prevent erroring
end)
but u put
success = pcall(function()
result = TeleportService:TeleportAsync(placeId, players, options) -- teleport the user in a protected call to prevent erroring
print(result)
end)
result is the value returned in the first block of code
idk how to explain :'D
Using the original code with 2 prints added in, I get the same result.
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 user in a protected call to prevent erroring
end)
print(success, result)
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
print(success, result)
return success, result
end
What’s odd for me is that the player is teleporting and successfully goes to the other place. The pcall returns true and it runs fine every time. But I can’t seem to get any result back from TeleportAsync.
I think that’s a built-in issue with teleportasync, it’s weird. Probably because of the fact that it sends a web request to roblox and what not. You should ignore it, all games have these weird errors with teleportasync even if it works properly.
If TeleportAsync errored, I would have no issues, I would call it again and expect it to work eventually.
My issue is that the API says a result will be returned. I need the result in order to pass data from the lobby to the server. If it couldn’t return me some sort of result it should have errored and let me try again.
Not sure if this is a related error with the TeleportAsync function, but I’m passing a TeleportOptions with ShouldReserveServer = true. When I join a server the game.PrivateServerId value is not set even though according to DataModel.PrivateServerId it should be set for all ReservedServers. I’m assuming this is related to the result of TeleportAsync not being returned.
Great news - Turns out TeleportOptions is an optional parameter for TeleportAsync and it won’t error if the value is not passed. Instead, if you pass the parameter, you get a result. If you don’t pass the parameter, you get no result, but it’ll teleport the players anyways.