"Attempt to index boolean with number" error with teleport service

Hello, I get this error for some reason and I’m not sure why…

This is my script:

game.ReplicatedStorage.Moderation.JoinGame.OnServerEvent:Connect(function(plr, targetId)
	print(targetId)
	local data = ts:GetPlayerPlaceInstanceAsync(targetId)
	local PlaceId = data[3]
	local instanceid = data[4]
	print(data)
	ts:TeleportToPlaceInstance(PlaceId, instanceid, plr)
end)
1 Like

TeleportService:GetPlayerPlaceInstanceAsync() returns a tuple, not a table, with the first item returned being a boolean. You’re receiving the error because you’re trying to index the boolean as if it were an array.

You can just type this to get the placeId and instanceid:

local _, _, placeId, instanceId = TeleportService:GetPlayerPlaceInstanceAsync(targetId)

Though, if you want to use a table instead, as if a table was returned rather than a tuple, you can table.pack() the returned values together:

local data = table.pack(TeleportService:GetPlayerPlaceInstanceAsync(targetId))

Also, you should wrap the calling of TeleportService:GetPlayerPlaceInstanceAsync() in a pcall, since the method might throw an error. Here’s an example:

local success, result = pcall(function()
    return table.pack(TeleportService:GetPlayerPlaceInstanceAsync(targetId))
end)

if not success then
    return
end

local placeId, instanceId = result[3], result[4]
--...
3 Likes

Worked perfectly, thanks. Did not know you can list variables like that.

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