Im trying to set a Block’s(Model) Rep’s(Primary Part) CFrame with a given position and orientation. The position is a table of {X,Y,Z} and the Orientation is the same with {OriX,OriY,OriZ}.
The script below sets the position perfectly, and prints out the ToEulerAngles of the orientation for debugging. EVERYTHING printed is correct, however, when Rep’s Orientation is set, its very wrong, but close.
--Create a Orientation CFrame
local orientationFrame = CFrame.fromEulerAnglesXYZ(math.rad(Block.Orientation[1]),math.rad(Block.Orientation[2]),math.rad(Block.Orientation[3]))
--local orientationFrame = CFrame.Angles(math.rad(Block.Orientation[1]),math.rad(Block.Orientation[2]),math.rad(Block.Orientation[3]))
--Print what the Orientation is supposed to be in X,Y,Z
print(P(0,"Orientation Recieved: ",unpack(Block.Orientation)))
--Convert CFrame orientation to EulerXYZ for debugging purposes
local oriX,oriY,oriZ = orientationFrame:ToEulerAnglesXYZ()
oriX,oriY,oriZ = math.deg(oriX),math.deg(oriY),math.deg(oriZ)
--Print result
--Repeat the above steps for adding the orientation CFrame to the Position CFrame
--(I figured seperating the CFrames might help with debugging. It didnt)
print(P(0,"OrientationFrame to EulerAngles: ",oriX,oriY,oriZ))
local TargetCFrame = CFrame.new(unpack(Block.Position))*orientationFrame
local TarX,TarY,TarZ = TargetCFrame:ToEulerAnglesXYZ()
TarX,TarY,TarZ = math.deg(TarX),math.deg(TarY),math.deg(TarZ)
print(P(0,"TargetCFrame ToEulerAngles: ",TarX,TarY,TarZ))
--Set the Rep CFrame (It looks very good at this point)
BlockClone:WaitForChild("Rep").CFrame = TargetCFrame
print("BlockRep Orientation: ",BlockClone.Rep.Orientation)
--The rep has a VERY WRONG Orientation from here)
Output log:
Things ive tried:
- Using :PivotTo()
- Using .CFrame = CFrame:ToWorldSpace()
- Taking Cframe * Cframe.angles initially
- Change CFrame.Angles to CFrame.FromEulerAngles()