TeleportService:GetPlayerInstanceAsync() issue

Hello,

I’ve recently been trying to achieve a system where someone can teleport to a game server a friend is currently in. I’ve been having some trouble with this however, it seems the roblox API reference’s entry on TeleportService:GetPlayerInstanceAsync() doesn’t provide accurate information as to what to expect from the returns. This is the relevant code:

local currInstance,placeId,instanceId
local s,m = pcall(function()
	currInstance,placeId,instanceId = ts:GetPlayerPlaceInstanceAsync(oPage.Id)
end)
print(currInstance)
print(placeId)
print(instanceId)

In this script ts is a direct reference to game:GetService('TeleportService') and oPage is a dictionary with the UserId of the target player at the Id key.

When I go to check out the results of those print statements I get the following:

true/false -- Changes, but seems to work as expected.

<placeId> -- The integer representation of the target place's game.PlaceId .

This is not what is expected, and seeing as I am getting no InstanceId, I am at a loss as to how to proceed. I’m unsure if I’m doing anything wrong, please inform me should this be the case.

I’ll be happy to provide any other info if deemed needed.

Relevant API reference entry: TeleportService | Documentation - Roblox Creator Hub

EDIT: Added the used variables for better understanding of the script excerpt provided.

1 Like

Oh I remember this problem. The documentation doesn’t match what GetPlayerPlaceInstanceAsync does, so it’s worth asking for documentation to be updated.

GetPlayerPlaceInstanceAsync actually returns four values, not three. The PlaceId is the third and the InstanceId is the fourth. The best way to debug something with tuple returns is to catch them in a table and then unload the values out.

local success, result = pcall(function ()
    return {game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(6809102)}
end)

if success then
    for index, value in ipairs(result) do
        print(index, value)
    end
end
Index DataType Item
1 Boolean Success value
2 String Error message
3 Integer PlaceId
4 String JobId

I have no idea why a success boolean and error message accompany this function when that can be done from a pcall so it’s pretty redundant, but, in either case, you need to account for this. So, in your case, you will actually need to be defining four variables.

local fetchSuccess, errorMessage, placeId, instanceId
local success, result = pcall(function ()
    fetchSuccess, errorMessage, placeId, instanceId = ts:GetPlayerPlaceInstanceAsync(oPage.Id)
end)
print(fetchSuccess)
print(errorMessage)
print(placeId)
print(instanceId)
2 Likes

That makes sense, didn’t think to look for a fourth return value.

That is, as far as my testing goes, not a return value but a boolean to determine wether or not the fetched JobId matches the one from the server the method was called from. (Simply put, it is true when the target player is in the same server as the user. Still pretty redundant, but worht noting nonetheless.)

And as a side note, the change request for the API reference entry is now in post approval in the Developer Hub category. Thanks for the assistance, @colbert2677 ! I can now work further on my game.