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

How do I make a player teleport to the direction they are facing?

Asked by 4 years ago

I've been thinking about a teleport script to teleport 10 studs to where the player was facing, but couldn't figure out how I would do it. I tried:

local orientation = character.Torso.Orientation
            character.HumanoidRootPart.Position = CFrame.new(character.Humanoid.RootPart.Position + 10, 0, 0)

but then I realized that it would teleport the player only in the X axis, and I don't know how to get the direction they are facing. I'm kinda new to this kinda stuff so I don't know what I'm doing.

0
I've been wondering the same thing. I'll be looking around online for the solution and If I find one I'll let you know SirDecent 7 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You should use CFrame.LookVector. LookVector is the forward-facing direction of a CFrame, or basically the front of a BasePart. (in your terms)

local humanoidRootPart = character.HumanoidRootPart
humanoidRootPart.CFrame = humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * 10 -- teleport the player 10 studs forward
Ad
Log in to vote
0
Answered by 4 years ago
function onTouch(part)
    if part.Parent.Humanoid ~=nil then
        part.Parent:MoveTo(script.Parent.Parent.Tele2.Position)

    end
end
script.Parent.Touched:connect(onTouch)

assuming you place a second part 10 studs right a head of the touched part. However, the direction of player when facing the part will till determine the direction facing when arriving on "Tele2".

Answer this question