Tweening Orientation does not get part to rotate on pivot point

I have a part with pivot point at one of the sides and when i rotate it in studio with the rotate tool, it rotates around the point. The orientation property changes as I do this.
However, when I tween the orientation in-game, it rotates on the origin.

What can i do to fix this?

If you set the orientation property on a part, it will always rotate around the origin, so if you want to rotate around the pivot, you need to rotate the part’s position around the origin instead.
To rotate a point around the origin, you need to do some basic trigonometry. If the point is at (x1,y1), and you want to rotate it by angle θ around the origin, you first need to convert it to polar coordinates:
r = sqrt(x1^2 + y1^2)
θ = atan(y1 / x1)

Then, add the rotation angle θ to θ and convert back to cartesian coordinates:
x2 = r * cos(θ)
y2 = r * sin(θ)

You can put this into a function that takes a CFrame and rotates it by a given angle around the origin:
function rotateCFrame(cframe, angle)
local r = cframe.position.magnitude
local theta = math.atan2(cframe.position.y, cframe.position.x) + angle
local x = r * math.cos(theta)
local y = r * math.sin(theta)
return CFrame.new(x, y, cframe.position.z)
end

Then you can just use this function and set the CFrame of the part:
local part = Instance.new(“Part”)
part.CanCollide = false
part.Anchored = true
part.Size = Vector3.new(10, 10, 10)
part.CFrame = rotateCFrame(CFrame.new(0, 0, 0), math.pi/2)
part.Parent = workspace

2 Likes