Rotate part according to other part

I have a rotation script, that when I press R, A part rotates on the Y axis.
I have this.
Screen Shot 2022-10-11 at 2.59.22 PM
When I press R I want this.


But I get this.

How do I get a part to rotate on another part? Like when you press Command+L to rotate a part?

Looks like you are rotating it on the world axis instead of the Part axis.

Please post the section of script that you are using since this is a Scripting Support question.

How would I change it to the part Axis using code?
current code-
After pressing R

	local MouseTarget = Mouse.Target
		local MouseHit = Mouse.Hit
			local Target = 	Plr.TroopTargetUnfinishedPlacement.Value
		
			local TargetY = math.rad(MouseTarget.Orientation.Y + Target.YRotation.Value)
			
		
	local X = MouseTarget.Orientation.X
	local Z = MouseTarget.Orientation.Z
			Target.YRotation.Value += IncreaseValueRotationValue
		 
			
				
			Target:PivotTo(CFrame.new(Target:GetPivot().Position) * CFrame.Angles(X,TargetY,Z) )--set orientation and position

What is IncreaseValueRotationValue set to?

Wait, I could be wrong, but I think you are reading

local TargetY = math.rad(MouseTarget.Orientation.Y + Target.YRotation.Value)

with math.rad but using

Target:PivotTo(CFrame.new(Target:GetPivot().Position) * CFrame.Angles(X,TargetY,Z) )

without math.rad.

IncreaseValueRotationValue is 45 degrees.

I am 99.9999999% sure that I use math.rad. Using * multiplies things, so if the rotation is already 45 degrees, It would change to 45 * 45 degrees.

Does it matter that you are using PivotTo? Can’t you just change the CFrame for the individual Part?

Yeah, I need to use PivotTo. It is required because I am using a model.

So is your Model PrimaryPart oriented the way you want the rotation to be?

Has the Pivot been edited at all?

To start, yes. The pivot constantly updates to where the players mouse is, but keeps it’s current rotation.