How to make Motor6D point to mouse.hit?

I find a script for my character to let his head look at the mouse pointing place.
But the head move so strangely.

This is my script

game:GetService("RunService").Stepped:Connect(function()
    local Hit = Mouse.Hit
    local Direction = Hit.p  + (Hit.LookVector * 5000)
    local HumanoidRootPartCFrame = HRP.CFrame
    local rotationOffset = (HumanoidRootPartCFrame - HumanoidRootPartCFrame.p):inverse()
    	
    PlayerRobot.Torso.Head.Transform =  rotationOffset * CFrame.new(Vector3.new(0, 0, 0), Direction) * CFrame.Angles(math.pi / 2, 0, 0)	 
 game.ReplicatedStorage:WaitForChild("PlayerHead"):FireServer(PlayerRobot.CamTo,PlayerRobot.Camerasubject)
end)

I believe the reason it is strange also depends on the rig,make sure the Motor6D is connected at the proper location, like for reference for R15, it’s located at the neck:

Here is another method with a different CFrame method for Motor6D or welds you can try out:

Thank you. I find that my motor6D is at the wrong place