TeleportAsync Not Returning a TeleportAsyncResult

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.

image

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
2 Likes

Found the original here: Teleporting Between Places | Documentation - Roblox Creator Hub

1 Like

If you are doing it in studio it will always fail, try testing in the actual published game on the website?

1 Like

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.

1 Like

i thhinkk its

    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

1 Like

I modified it to that just so I could print inside of the pcall itself and see what it was returning.

1 Like

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

image

1 Like

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.

1 Like

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.

1 Like

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.

1 Like

Try printing the properties of the teleportresult and see if that changes anything although it shouldn’t really.

Such as the privateserverid or reserveserveraccesscode

1 Like

I can’t print any of the values because the result is nil.

1 Like

Tried it anyways and got the expected error:

1 Like

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.

1 Like

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.

1 Like

Roblox should update the documentation then, kinda confusing.

1 Like

Agreed, I’ve already submitted a pull request on the creator docs github page for updated documentation.

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