How to read/get certain values in a Tuple?

I am using GetPlayerPlaceInstanceAsync to find out where the player is. This returns a Tuple, which I thought I could access like table and do something like this:

local check = game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(UserId)
print(currentcheck[“placeId”])

Which gave me the error attempt to index a boolean, I also tried:

local check = game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(UserId)
print(currentcheck[3])

Both return the same thing in the end, I printed just check. It was just printing the first value in the tuple, the success. How would I go about checking placeId or for any other value of a tuple for future reference?
Here is the wiki pages on GetPlayerPlaceInstanceAsync and Tuples.

I think you missed the answer on the Tuple page you linked yourself;

local part, position = Workspace:FindPartOnRay(ray)

Their example assigns the first returned value of the tuple to part, and the second to position.

Alternatively you can use the table constructor around anything that returns a tuple to put the returned values into a table with numeric indices.

2 Likes

You can collect the returns of a function in a table, like so:

local returns = {fn(...)};
print(unpack(returns));

:GetPlayerPlaceInstanceAsync returns multiple values, not a table containing those multiple values.

And if you know how many return values there are, you can of course collect them manually:

local ret1, ret2, ret3 = fn(...); --// assuming `fn` returns 3 values
3 Likes

Thank you for the wonderful response! This allowed me to wrap my head around everything nicely.

I read it but sometimes when I read I don’t actually intake the information. Thank you for explaining.