Orientating and Repositioning Npc's arms to face target

  1. What do you want to achieve?
    This is a reupload of an article that was unsolved. Since then there have been some improvements, the current issue is the Npc’s are able to orientate to the target’s position but its arms are positioned wrong. This Npc is an R15 rig and uses an animation when trying to change its Cframe. So since this Npc is a R15 rig, I was unable to use the method I did for the Npc’s head.

  2. What is the issue? Include screenshots / videos if possible!
    Video with character’s arms repositioned wrong.

Video with character’s arms positioned correctly, and does not follow while target is anchored. (Video 1)

Video 2

  1. What solutions have you tried so far?
    This is one of the solutions that repositions the character’s arms wrong
while true do
	task.wait()
	local goalCF = CFrame.lookAt(Head.Position, target.PrimaryPart.Position, upperTorso.CFrame.UpVector)
	neckJoint.C0 = worldCFrameToC0ObjectSpace(neckJoint,goalCF)

	leftMotor6.C0 = CFrame.new(CFrame.lookAt(leftMotor6.C0.Position,Vector3.new(root.Position.X,target.PrimaryPart.Position.Y,root.Position)).LookVector)*CFrame.Angles(math.rad(target.PrimaryPart.Position.Y), 0, 0)
	rightMotor6.C0 = CFrame.new(CFrame.lookAt(rightMotor6.C0.Position,Vector3.new(root.Position.X,target.PrimaryPart.Position.Y,root.Position)).LookVector)*CFrame.Angles(math.rad(target.PrimaryPart.Position.Y), 0, 0)

end

This is a solution that positions character’s arms correctly, but does not orientate properly

runService.Heartbeat:Connect(function()
	leftMotor6.C0 = CFrame.new(leftMotor6.C0.Position) * CFrame.Angles(-workspace.Zombie.UpperTorso.CFrame.LookVector.Y, 0, 0)
	rightMotor6.C0 = CFrame.new(rightMotor6.C0.Position) * CFrame.Angles(-workspace.Zombie.UpperTorso.CFrame.LookVector.Y, 0, 0)
	headMotor6.C0 = CFrame.new(headMotor6.C0.Position) * CFrame.Angles(-workspace.Zombie.UpperTorso.CFrame.LookVector.Y, 0, 0)
end)

Here you go

local runService = game:GetService("RunService")
local rig = game.Workspace.Rig
local rightMotor6 = rig.RightUpperArm.RightShoulder
local leftMotor6 = rig.LeftUpperArm.LeftShoulder
local headMotor6 = rig.Head.Neck
local zombie = workspace.Zombie

runService.Heartbeat:Connect(function()
	local direction = (zombie.PrimaryPart.Position - rig.PrimaryPart.Position).Unit
	local dot = direction:Dot(rig.PrimaryPart.CFrame.UpVector)
	local radians = math.acos(dot) + (-math.pi / 2)
	
	leftMotor6.C0 = CFrame.new(leftMotor6.C0.Position) * CFrame.Angles(-radians, 0, 0)
	rightMotor6.C0 = CFrame.new(rightMotor6.C0.Position) * CFrame.Angles(-radians, 0, 0)
	headMotor6.C0 = CFrame.new(headMotor6.C0.Position) * CFrame.Angles(-radians, 0, 0)
end)

Edit: You might need to swap back to uppertorso instead of primarypart if it causes issues with your animation

This works perfectly. Thank you, I would have never got this.