Make a proper rotate system

Hello there! I want to make a rotate system that rotates part using key presses. But I dont know how to proper change orientation. Sometimes when you rotate a part using 1 axis,it changes for example X and Z of orientation.

But I could make only rotate system that changes only one axis and this occurs:
robloxapp-20220309-2203210.wmv (1.9 MB)
So how to make a rotate system like in studio?

1 Like

Roblox studio has the option to rotate in world space and in local space.

I wrote a tutorial with some examples, hope they help:

Can you explain that is Rx,Ry,Rz here
Part.CFrame = CFrame.Angles( Rx, Ry, Rz ) * ( Part.CFrame - Part.CFrame.Position ) + Part.CFrame.Position
is it just an orientation in rads?

Kinda except it’s not orientation though it is in radians.

Use CFrame.fromOrientation if the values are orientation values.

CFrame.Angles the order which the angles are applied in is different and will lead to bugs if used as orientation.

To rotate a part adding the same value i need to do this?:

local Part = script.Parent

local rad = math.rad

while true do

local cframe = script.Parent.CFrame

local Rx,Ry,Rz = cframe:ToOrientation()

Ry+=rad(30)

local rx, ry, rz = Part.CFrame:ToEulerAnglesYXZ()

print(rx + Rx, ry + Ry, rz + Rz)

Part.CFrame = CFrame.fromEulerAnglesYXZ( rx + Rx, ry + Ry, rz + Rz ) + Part.CFrame.Position

wait(3)

end
end