Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the best way to teleport? Has the least bugs

Asked by 6 years ago
Edited 6 years ago

There are many ways like using a Body Position(false teleporting), or Torso Positioning with CFrame. But what is the best way to teleport which causes the least bugs.

Example one: This uses CFrame

local debounce = true
local Tele2 = game.workspace.ExampleVariablePart

script.Parent.Touched:connect(function(hit)
    if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
        debounce = false
        hit.Parent.Torso.CFrame = Tele2.CFrame
        wait(1)
        debounce = true

    end
end)

Example two: This uses a bodyposition

local debounce = true

script.Parent.Touched:connect(function(hit)
    if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
        debounce = false
        local BP = Instance.new("BodyPosition")
        BP.Parent = hit.Parent:FindFirstChild("HumanoidRootPart")
        BP.Position = Vector3.new(0,0,0) -- example
        wait(1)
        debounce = true

    end
end)

The answer may not even be one of these examples but I just need the best way

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

If all you need is to set the Vector3 position of the character,

local teleportTo = Vector3.new(100, 10, 100)
character:MoveTo(teleportTo)

works just fine.

However, if you need to make sure the character is rotated a certain way, you must use CFrame on one of the character's body parts. To easily ensure compatibility between R6 and R15 rig types, just use the HumanoidRootPart, which exists in both rig types.

For example, if I want to make sure the character is facing the center of the map after being teleported...

local teleportTo = Vector3.new(100, 10, 100)
local lookAt = Vector3.new(0, 0, 0)
character.HumanoidRootPart.CFrame = CFrame.new(teleportTo, lookAt)
Ad
Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago

:MoveTo() Lel

Answer this question