We use cookies on this site to enhance your user experience

Teleport Within a Place

Teleport Within a Place

Jul 03 2018, 10:25 AM PST 5 min

Teleportation is a term given to the act of moving a group of parts, typically a player’s character, to a certain coordinate. In Roblox, setting the Position property of a parts would disconnect the part from any other parts connected to it and break the model. Therefore, one cannot use the following to teleport a player because it would disconnect the Torso from the Head. Doh!

game.Workspace.Player.Torso.Position = Vector3.new(0, 50, 0)

To correctly teleport a player without killing them, you must use the CFrame property and use the Articles/Understanding CFrame|CFrame data type instead.

game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 50, 0))

CFrame versus MoveTo

Humanoid/MoveTo|MoveTo can be used in place of setting the CFrame of one brick in the model. MoveTo will only change the Position/CFrame of the parts in the model if the Parent property is the Workspace.

Teleporting All Players

One can teleport all players in the game by iterating over each one of their Characters and setting the CFrame accordingly.

Be careful when teleporting a group of players at the same time: offset the target positions so that the players' torsos do not overlap.
target = CFrame.new(0, 50, 0) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
   --Make sure the character exists and its HumanoidRootPart exists
   if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
       --add an offset of 5 for each character
      player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)

The above code would teleport each player to the position (0,50,0), going up 5 for each character so they do not overlap. Obviously, placing the offset above a player helps avoid collisions, but if they are teleporting into a buildig or room, then you may end up placing a player above the ceiling or roof. Take time and care when creating your teleport logic to avoid these edge cases.

Teleportation Effects

You can add in fading effects by using Articles/For Loops|for loops to incrementally increase the Transparency of your limbs.

player = game.Players.Player --you might want to change this...
target = Vector3.new(20, 10, 20) --...and this

function fadeTo(a, b, c)
    for transparency = a, b, c do
    --go from a to b, counting by c

        for _, part in pairs(player.Character:GetChildren()) do
        --for each of the objects in the character,

            if part:IsA("BasePart") then
            --check if it's a part, and if so

                part.Transparency = transparency
                --set its transparency

fadeTo(0, 1, 0.1) --fade out,
player.Character.HumanoidRootPart.CFrame = target --teleport the player
fadeTo(1, 0, -0.1) --fade back in

Other effects may include making the player rise up off the ground, become shiny by changing BasePart/Reflectance, or spin using BodyAngularVelocity.

  • teleport
  • coding