Rotate part based on CFrame.LootAt direction

I want to get a CFrame rotation like this:
We have a part and we look at it,
Screenshot (289)
And then I want to get a rotation like this:
Screenshot (290)
but not actually rotate the part itself but setting its pivot rotation maybe.
I need the Y axis to change direction.
I want a CFrame returned btw.

Rotation of CFrame is presented as direction, you can do CFrame:ToOrientation to get x,y,z rotation of it

I don’t want to just get the rotation of the part.

I think I’ll edit it a little bit.

It’s not rotation of the part but rotation of the CFrame

But that’s just getting the rotation of the CFrame of the part?

it’s anchored yet or not ? (bonus text)

It’s not anchored as it’s for a grabbing system.

I’m going to sleep now so I’ll check on this tomorrow.

hmm if u want to know the rotation only then how abt

print(Part.CFrame.Rotation)

im not sure if this will be work

If it’s Part’s cframe then it will return part’s rotation in 3 numbers

Nah, CFrame.LookAt or CFrame:ToOrientation() gives rotation

I don’t want to get a rotation I want to set the rotation pivot point of the part so it will rotate differently.

I can’t tell if what you want is CFrame.UpVector or something else

Did you click Edit Pivot before rotating the handle?

Can’t really tell what you want but this my shot…

LookAt

local part = workspace.Part -- The part you want to rotate
local target = workspace.Target -- The object you're looking at

-- Get the current position of both objects
local partPosition = part.Position
local targetPosition = target.Position

-- Create a new CFrame using LookAt, but only alter the Y-axis by setting the Y value of both part and target to the same level
local lookAtCFrame = CFrame.lookAt(partPosition, Vector3.new(targetPosition.X, partPosition.Y, targetPosition.Z))
part.CFrame = lookAtCFrame

Pivot

local part = workspace.Part -- The part you want to rotate
local pivotPoint = workspace.Pivot.Position -- The desired pivot point (can be another part's position or a specific Vector3)

-- Create an offset from the pivot point to the part's current position
local offset = part.Position - pivotPoint

-- Create a new CFrame to rotate around the pivot
local rotationAngle = math.rad(45) -- Example rotation angle in radians (rotate by 45 degrees)
local newCFrame = CFrame.new(pivotPoint) * CFrame.Angles(0, rotationAngle, 0) * CFrame.new(offset)
part.CFrame = newCFrame

I’ve got something close to what I want.
I set the pivot offset of the part with CFrame.LookAt, making the pivot offsets rotation face the players head; while the player is grabbing the part, I use CFrame.LookAt again from the part to the players head to rotate it. It works but I think it flips around on the negative axis so I need that fixed.
Here’s a video of what I currently have:

I think the CFrame.LookAt when setting the pivot offset turns the non vertical axis and then when I use PivotTo() to turn it with CFrame.LookAt, it turns around? I’m not exactly sure. I just need help.

what you’re trying to do is have the same “side” of the part face you regardless of where you turn it, right?

If you mean make the part face me in the same direction the part originally was when first picked up, then yes.

I made it work a little better but now have a slightly different problem. Previously I’ve not provided code so I will now. Video will show that the part would flip horizontally sometimes:

Here’s the code:

--On grab
local newPivotOffset = CFrame.lookAt(rayResult.Position, character.Head.Position).Rotation
					item.MovePoint.PivotOffset = item.CFrame.Rotation * newPivotOffset
--MovePoint is a part that gets moved so the item will follow it. This uses an AlignPosition and AlignRotation.
					item.PivotOffset = item.CFrame.Rotation * newPivotOffset

--HeartBeat
item.MovePoint:PivotTo(CFrame.new(newCFrame) *
				CFrame.lookAt(newCFrame, character.Head.Position).Rotation)
--newCFrame is just the new position.