CFrame defaulting my parts' orientation to 0

I have ported an elevator system I made from one game to another, and now whenever a CFrame is called, the Orientation is set to (0, 0, 0). This wasn’t an issue in my previous game, which conveniently had the elevator system already facing that way.

But now, I’ve rotated the system to suit my needs, setting its initial orientation to (0, -90, 0), giving the result as shown here:

ezgif-3-a7d6908f4f\

The elevator is facing the wrong direction, as a CFrame is called at the start of its script.

local RootPart = game.Workspace.ElevatorSystem.Elev.ROOT -- Root Part which has the same sizing and positioning as the Elevator Model object. All parts that make the Elevator model up are welded to this Root Part.
local newCFrame = CFrame.new(-28.15, -6.4, 83.35)
RootPart.CFrame = newCFrame

The doors are normal at first, as their CFrams is only called when the button is pressed, which calls a Tween function to the CFrame.

-- RED

local goal = {}
goal.CFrame = CFrame.new(-20.15, -6.6, 76.55) -- to open
wait(0.5)			

local tweenInfo = TweenInfo.new(3)
local tween = TweenService:Create(TopRedRootPart, tweenInfo, goal)
tween:Play()

wait(2)

-- MESH

local goal = {}
goal.CFrame = CFrame.new(-20.15, -9, 76.35) -- to open			

local tweenInfo = TweenInfo.new(2)
local tween = TweenService:Create(TopMeshRootPart, tweenInfo, goal)
tween:Play()

wait(2.5)

I tried reading the Dev Wiki entry on CFrame, but was unable to decipher the issue from the information present. I also tried looking for anyone else on the Dev Forum who may have had a similar issue, but was unable to find any in my search queries.

It should also noted that no scripts have printed any errors to Output. If anyone can help me solve this issue, I would greatly appreciate it.

You can use Look Vectors in CFrames default instantiation to determine the rotation, but what you should probably use is CFrame Angles. This Roblox article shows you how to do it.

You pretty much “multiply” your CFrame using the CFrame Angles like so:
local cf = CFrame.new(0, 5, 0) * CFrame.Angles(math.rad(45), 0, 0)

Keep in mind Cframe.Angles takes radians, so if you want to use degrees, use the math.rad() function as you can see in the example above.

Let me know if you have any other questions.

1 Like

Just threw it in as the following to fit my use case:
local cf = CFrame.new(-20.15, -6.6, 76.55) * CFrame.Angles(0, math.rad(-90), 0)

It worked, thank you for your help!

1 Like