Rotating Part Does not rotate along X axis

I have created a model which is cloned and then positioned in place. My problem is when the object is rotated the X-axis doesn’t change but suspected x-axis is added to the Z-axis, So in

model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(math.rad(-65),math.rad(90),math.rad(-65)))

The expect Orientation would be (-65,90,-65) But this does not happen and instead it is (0,90,-130)

I don’t have a clue of what would be causing this. Here is the original code for Reference:

repeat wait(.1) until script.Parent.Parent.Name ~= "Ship"
---Variables
local name = script.Parent.Parent.Name
local ship = script.Parent.Parent
local model = workspace[name]

---Cloning
model.Archivable = true
local maid = model:Clone()
maid.Archivable = false
model.Archivable = false

----Parent
maid.Parent = script.Parent
maid.Humanoid.PlatformStand = false

----Position
script.Parent.PrimaryPart.Anchored = true
maid.PrimaryPart.Anchored = true

local pillar = script.Parent.Rod
local rodx = pillar.Position.X
local rody = pillar.Position.Y
local rodz = pillar.Position.Z
maid:SetPrimaryPartCFrame(CFrame.new(rodx,rody-0.5,rodz))
maid:SetPrimaryPartCFrame(maid:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(math.rad(-65),math.rad(90),math.rad(-65)))

----Weld


local weld = Instance.new('Weld')
weld.Part0 = ship.PrimaryPart
weld.Part1 = maid.PrimaryPart
local c = CFrame.new(script.Parent.PrimaryPart.Position)
local c0 = script.Parent.PrimaryPart.CFrame:Inverse()*c 
local c1 = maid.PrimaryPart.CFrame:Inverse()*c
weld.C0 = c0
weld.C1 = c1
weld.Parent = maid.PrimaryPart
--maid.PrimaryPart.Anchored = false
--script.Parent.PrimaryPart.Anchored = false


This Is a script inside another model and clones the player model and positions it. (My last post)

I don’t understand your problem exactly is, but I think you mean it’s adding the rotation to the original one instead of creating a new one.

model:SetPrimaryPartCFrame(CFrame.new(model.Position)*CFrame.fromEulerAnglesXYZ(math.rad(-65),math.rad(90),math.rad(-65)))

I’m not trying to add to it but replace it instead. It just no matter what number I change the x axis always stays 0

1 Like

Would platform stand be related to this issue, even if that would not explained the (-65) adding to the (-65) for (-130)

1 Like

Did you try the code I gave you?

I modified it to this:

maid:SetPrimaryPartCFrame(CFrame.new(maid.PrimaryPart.Position)*CFrame.fromEulerAnglesXYZ(math.rad(-65),math.rad(90),math.rad(-65)))

but the same issue continues to happen

Heres a pic also

1 Like

Maybe this is because of Gimbal Locking. Try separating the rotations or performing them in a different order.

If pasting that same orientation into an object changes it, then that also means this is happening.
Here is a visual of your rotation, however:
https://i.gyazo.com/40b08b81d7eef30c539a33a7dc194676.mp4
This is from a static <0, 0, 0> orientation.
Notice how the object now has no rotation about the X axis!!!

1 Like

I did some testing and when i just rotate x axis, this works, but adding the y axis causes this “Gimbal Locking”. What would be the best way to individually rotate along each axis then?

1 Like

It is mostly about just using the proper angles for the rotation. Euler angles have the possibility of locking very easily so it is always good to check the results with actual parts or try other rotations.

1 Like

I tried doing this:

maid:SetPrimaryPartCFrame(maid:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(math.rad(-65),math.rad(0),math.rad(0)))
wait(3)
maid:SetPrimaryPartCFrame(maid:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(90),math.rad(0)))

Line 1 works but Line 3 makes it (0,90,-65) still even though the z value wasnt changed.

1 Like

Try using my axis rotation debugger and seeing the results in the output:
https://www.roblox.com/library/4808422878/Rotation-Example

  Rotation about the X axis by -65°
  Result: -65, 0, 0
  Rotation about the Y axis by 90°
  Result: 0, 90, -65
  Rotation about the Z axis by -65°
  Result: 0, 90, -130

Notice how when you rotate about the Y axis, you immediately lose that X rotation!!
Here are the results of that same rotation, but applied in X, Z, Y order:

  Rotation about the X axis by -65°
  Result: -65, 0, 0
  Rotation about the Z axis by -65°
  Result: -65, 0, -65
  Rotation about the Y axis by 90°
  Result: 22.52, 27.23, -78.85
2 Likes

So what would you recommend if i want the final rotation to be (-65,90,0) ?

Oh wait, so when you rotate Y 90*, the X axis become the Z axis, and the Z axis becomes the Z axis becomes the X axis?

1 Like

Rotate a part in the way you want it to be rotated. Then, use those same values in your orientation.
You can use the debugger if you want to see what happens to the values. If it helps, Orientation applies rotations in Y, X, Z order, which can be used with CFrame.fromEulerAnglesYXZ(Y, X, Z)

Watch what happens when you use this order in the debugger.
https://i.gyazo.com/3d04cc53f9cbf935b95c70030c2ef174.mp4

1 Like

I did the Opposite with:

--CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(0),math.rad(65)))
wait(3)
--CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(90),math.rad(0)))

This Gave the effect I wanted thanks.

1 Like

Try using the above solution instead. This is also very useful when dealing with things like Cameras, because they will have improper rotations if applying them in the wrong order.
Example:
https://i.gyazo.com/b142157632b1c08e6c7a40cc124813a9.mp4
Left-side camera is tilted while the right-sided one is properly rotated.
Both are using <65, 90, 0>, but the order in which the rotations happen change. (X, Y, Z vs Y, X, Z)

2 Likes