We use cookies on this site to enhance your user experience

Following a Player in a Game Universe

Following a Player in a Game Universe

Sep 10 2018, 4:53 AM PST

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)