Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How may I teleport a player in front of another player?

Hello! Thank you for helping in advance.

So I've been currently working on this animation that when a player clicks a certain "X" for this case, and if the magnitude is sufficient then the player should be teleport and the animation would be basically the player's hand touching the other player's shoulder. My main question is, by either changing the CFrame of the HumanoidRootPart or using the:MoveTo(). How may I Teleport the player in front of another? I've tried using CFrame or MoveTo() yet sometimes it teleports the player behind or the player is facing the wrong direction.

1 comment

0

Vector3

1 answer

✓ Accepted answer

CFrames can be used with two vectors. The first vector is the cframe position (where you will be teleported) and the second vector is the cframe direction (where you will be looking).

To get the looking vector of a player, you can use part.CFrame.LookVector. It creates a vector pointing to the looking direction of a part.

If you want to teleport in front of the other player and look at it, maybe this will work:

local rootPart = target.HumanoidRootPart
myChar.HumanoidRootPart.CFrame = CFrame.new(rootPart.Position+(rootPart.CFrame.lookVector*3),rootPart.Position)

1 comment

0

Thank you! It works!

This discussion is preserved as it was. New answers, comments, and votes are closed.