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

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

Asked by 3 years ago
Edited 3 years ago

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.

0
Vector3 no0bgaming748 24 — 3y

1 answer

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
3 years ago
Edited 3 years ago

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)
0
Thank you! It works! EliteForce1420 4 — 3y
Ad

Answer this question