PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetPlayerPlaceInstanceAsync

This function returns the DataModel/PlaceId and DataModel/JobId of the server the user with the given Player/UserId is in provided it is in the same game as the current place.

TeleportService/TeleportToPlaceInstance can then be called with this information to allow a user to join the target user’s server.

This function returns the following values:

# Name Type Description
1 success bool A bool indicating if the user was found in the same game universe
2 error string An error message in the event of the lookup failing
3 placeId int64 The `DataModel/PlaceId` of the server the user is in
4 instanceId string The `DataModel/JobId` of the server the user is in

Caveats

You should be aware of the following limitations when using this function:

  • This function can only be called by the server
  • This function may fail to return the correct information if the user is teleporting
  • It is possible for this function to throw an error, hence developers should wrap it in a pcall (see example below)
  • As this function returns the DataModel/JobId of the server and not the access code returned by TeleportService/ReserveServer the id returned is not appropriate for use with reserved servers

See also

  • For the DataModel/PlaceId|PlaceIds and DataModel/JobId|JobIds of a Player|Player’s friends, use Player/GetFriendsOnline

Parameters

Name Type Default Description

The Player/UserId of the Player

Returns

Return Type Summary

See the table above


Code Samples


Following a Player in a Game Universe

The code sample below, when placed inside a Script in ServerScriptService will teleport users following another user to the place and server that user is in. Note, this will not work if the user is in a reserved server.

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    -- is this player following anyone?
    local followId = player.FollowUserId
    if followId then
        -- if so find out where they are
        pcall(function()
            local success, errorMessage, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(followId)
            -- have we found this player?
            if success then
                -- if so teleport
                TeleportService:TeleportToPlaceInstance(
                    placeId,
                    jobId,
                    player
                )
            end
        end)
    end
end)