I’m trying to make a rotatable cannon but sometimes the cannon starts to go on its side like so:

Everything turns right/left/up/down on queue but it is still possible for you to lay on your side like that. Therefore, I tried to remove the Z rotation part by setting it to 0 no matter what.

– adjust the cframe by the y-angle and the x-angle.

Body.CFrame = Body.CFrame * CFrame.Angles(0, math.rad(yAngle), 0) * CFrame.Angles(math.rad(xAngle), 0, 0)

```
local x,y,z = Body.CFrame:ToEulerAnglesXYZ()
```

– if the body tilted to the side, then no worry. reset that tilt back to zero and preserve the other old angles.

Body.CFrame = CFrame.new(Body.Position) * CFrame.Angles(x, y, 0)

Clearly I lack an understanding of CFrames because instead my cannon seems to flick back and forth in arbitrary rotations. (Also where is that script formatting option so I can format my code?)