Hi, I'm trying to make a script that makes a part's rotation the same as the players Torso's lookVector, however I'm having a ton of trouble getting this done. This is what I have done so far, however as you can see the part doesn't rotate with the player's torso. Any tips/advice on what I can do to fix this?
How to constantly have 2 parts have the same lookVector/Rotation?
1 answer
You are given two parts: one named Torso and another part named OtherPart. What you're trying to do is make OtherPart copy the rotation of Torso.
A CFrame is a combination of two matrices: a position matrix/vector (The one returned by CFrame.p) and a rotational matrix (not trivial to extract).
You can use CFrame:components() to return all the components of a CFrame:
x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = CFrame:components()
where x, y, and zare the components of the position vector and R00 through R22 are the components of the rotational matrix.
There is also a constructor for CFrames so that you can plug these 12 values in to get the same exact CFrame.
newCFrame = CFrame.new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22)
What you want to do is make a CFrame containing the x, y, and zcomponents of OtherPart's CFrame while copying the R00 through R22 components of Torso. You would do something similar to this:
local x, y, z,
_, _, _,
_, _, _,
_, _, _ = OtherPart.CFrame:components()
local _, _, _,
R00, R01, R02,
R10, R11, R12,
R20, R21, R22 = Torso.CFrame:components()
OtherPart.CFrame = CFrame.new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Alright, thank you for the help! I'll work on it a little more and see if I can get it to work while learning.