Issue with using character's Y orientation

local function snapRotation(target, snappedZRad)
	
	if target and target.Name ~= "ATTACHMENT" then return end
	if not target then return end
	
	local primaryPart = target.Parent.PrimaryPart
	if not primaryPart then return end

	local cframe = primaryPart.CFrame
	
	local rY = math.rad(char.Head.Orientation.Y)

	target.Parent:SetPrimaryPartCFrame(CFrame.new(cframe.Position) * CFrame.Angles(0, rY -math.rad(90), snappedZRad))
	
end

so, the issue is rY is behaving odd once the player turns to a certain angle, for example; if the player is within that certain angle and stops holding the item they are carrying, and picks it up again the item will be in a new orientation.

my goal was to have the item match the character’s rotation but it’s obviously not working and i’m stuck on how to fix this.

Orientation is weird and doesn’t always work as expected, whenever I try to get the rotation of something I do this which seems to work

local _, radiansY = Part.CFrame:ToEulerAnglesXYZ()
local degreesY = math.deg(radiansY)

your example made it behave even worse, where now it doesn’t follow the characters orientation at a certain angle and instead spins on its axis

edit: i literally have no clue what is causing this

well from my experimentation, the X and Z values of the cframe:ToEulerAnglesXYZ() are somehow tied to the Y value, how can i ignore the Y value?