Odd behavior on R6 Head Movement when animation is applied

Hello,
I’ve recently tried to remake a system that I previously had for head movement for a fighting game I’m working on but seem to not be able to get the CFrame to be exactly to how I want it to be.

I want to achieve the ability to have the head movement be forever in the same direction as the Humanoid RootPart (like the R6 Idle) and always being able to look in the direction of the mouse while also not being affected by animations.

The problem is that the head’s calculations are skewed whenever an animation that’s complex (that, for example, turns the head almost 90 degrees, because the torso is severely tilted).

How do I stop this?
I’ve tried lerping the Transform of the neck (seeing as I still want it to have the same animation), i’ve disabled Retargeting among other things.

Here’s an example:
Normal R6 Idle (works fine)

A different idle that my game uses (All of a sudden up goes left?)

Here’s the code for the head movement (it’s a bit messy, as would any calculation-based script would):

local function GetMouseHit(Mouse,raycastParams)
	local ray = Mouse.UnitRay
	local raycastResult = workspace:Raycast(ray.Origin, ray.Direction * 1000, raycastParams)
	if raycastResult == nil then
		return ray.Origin + ray.Direction * 1000
	else
		return raycastResult.Position, raycastResult.Instance
	end
end


function HeadMovement(Mouse,plr,Head,torso_lv)
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	if plr:IsA("Model") then
		raycastParams.FilterDescendantsInstances = {plr}
	else
		raycastParams.FilterDescendantsInstances = {plr.Character,workspace.CurrentCamera,workspace.FX,workspace.PlayerHitboxes}
	end
	local aaa,aaa2 = GetMouseHit(Mouse,raycastParams)
	local Point = aaa or plr.Character.Head.Position
	local Dist = (Head.CFrame.p-Point).magnitude
	local Diff = Head.CFrame.Y-Point.Y
	local HeadHorFactor = .75
	local HeadVertFactor = .5
	local headpos = Head.CFrame.Position


	local export_table = {X = math.asin(Diff/Dist)*HeadVertFactor,Y = (((headpos-Mouse.Hit.Position).Unit):Cross(torso_lv)).Y*HeadHorFactor}
	return 	export_table
end

function Defaults( dt,Player, HumanoidRootPart, Humanoid, Torso,CameraCF,Mouse )
	local XSensitivity = 8 --The lower, the more sensitive. Reccomended 8
	local YSensitivity = 6 --The lower, the more sensitive. Reccomended 6
	local HeadMovementTable = HeadMovement(Mouse,Player,Torso.Parent.Head,Torso.CFrame.LookVector)
	local NeckResult = NeckOriginalC0 *CFrame.Angles(0,HeadMovementTable.X,HeadMovementTable.Y)
	local LerpTime = 1 - LerpSpeed ^ dt
	Torso.Neck.C0 = Torso.Neck.C0:Lerp(NeckResult, LerpTime)

end

Any help would be very much appriciated. Thanks!

Try setting workspace.Retargetting to Disabled and try again.
It might not work, but if it does it would save you a bit of time.

As I said previously, I have done that already in one of my attempted solutions.