TeleportService guide

TeleportService is used to teleport players from one place to another without the user having to go through the website. This can be used to teleport players between places in a game or even to another game. TeleportService is required for users to access places created with AssetService.

How to Use[edit]

Teleport service can be called both in Scripts and LocalScripts. The functions in both cases are used the same, except that Scripts have to provide a Player object (this object is implicitly the LocalPlayer when used in a LocalScript).

Most of the functions in TeleportService require the id of the place to teleport the player to. This id can be obtained in several ways. If the destination place is in the same game as the place the player will be teleporting from, the id can be obtained from the Game Explorer by right clicking on the place and selecting Copy ID to Clipboard.

TeleportServiceGuideCopyIDtoClipboard.png

The id can also be obtained from the ROBLOX website. The id of each place is in the URL of that place:

PlaceIdInUrl.png

The place id can then be used to teleport a player:

local TeleportService = game:GetService("TeleportService")
 
local level1Id = 408502340
local level2Id = 408502380
 
game.Players.PlayerAdded:connect(function(player)
	TeleportService:Teleport(level1Id, player)
end)

Valid Teleport Destinations[edit]

TeleportService has limits on the places a player can be teleported to. A player can only be teleported between places in the same game or to the Start Place of another game:

TeleportServiceValidDestinations.png

Examples[edit]

Teleport when part touched[edit]

In this example, Teleport is used to teleport a player when they touch the part the teleport script is parented to.

local TeleportService = game:GetService("TeleportService")
local level1Id = 408502340
local level2Id = 408502380
 
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:Teleport(level1Id, player)
    end
end
 
script.Parent.Touched:connect(onTouched)

Teleport to Named Spawn[edit]

In this example, TeleportToSpawnByName is used to teleport a player to a specifically named SpawnLocation in the destination place.

local TeleportService = game:GetService("TeleportService")
local level1Id = 408502340
local level2Id = 408502380
 
local level1SpawnName = “SpawnLocation1”
 
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then TeleportService:TeleportToSpawnByName(level1Id , level1SpawnName, player)
    end
end
 
script.Parent.Touched:connect(onTouched)

See Also[edit]