NPC's arms rotating in a weird way

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a gun NPC with a rifle, and currently I am making him “aim” and look at a part.
  2. What is the issue? Include screenshots / videos if possible!
    He looks at the part correctly, but his arms seem to rotate strangely: https://gyazo.com/d6387cd21b12c79cf2b766a3c14a4b23
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried to search for solutions, but none are good for my problem.
    Script:
wait(0.1)
local c1 = script.Parent.HumanoidRootPart["Root Hip"].C1
local neckc1 = script.Parent.Torso.Neck.C0
local lshc = script.Parent.Torso["Left Shoulder"].C0-- * CFrame.Angles(0,math.rad(-90),0) * CFrame.new(0.5,0,-0.5)
local rshc = script.Parent.Torso["Right Shoulder"].C0-- * CFrame.Angles(0,math.rad(90),0) * CFrame.new(-0.5,0,-0.5)
local debugging = false
--[[local idle = script.Parent.Humanoid.Animator:LoadAnimation(script.Idle)
for i=1, 100 do
	idle:Play()
end]]
local function forloop()
	if script.Target.Value ~= nil then
		local target = script.Target.Value
		local rot = math.atan2(target.Position.Z-script.Parent.HumanoidRootPart.Position.Z,target.Position.X-script.Parent.HumanoidRootPart.Position.X)
		local angle = math.deg(rot) + script.Parent.HumanoidRootPart.Orientation.Y + 90
		if angle > 180 then
			angle = -(360-angle)
		end
		script.Parent.HumanoidRootPart["Root Hip"].C1 = CFrame.Angles(math.rad(90),math.rad(180),math.rad(angle))
		local vec = (target.Position - script.Parent.Head.Position)
		vec = Vector3.new(vec.X,-vec.Y,vec.Z)
		if debugging == true then
			workspace.debug.Position = vec + script.Parent.Head.Position
			print(vec)
		else
			workspace.debug.Transparency = 1
		end
		local cf = script.Parent.Torso.CFrame:ToObjectSpace(CFrame.lookAt(script.Parent.Torso.Position, vec + script.Parent.Head.Position))
		script.Parent.Torso.Neck.C0 = neckc1 * cf
		local vec = (target.Position - script.Parent["Left Arm"].Position)
		vec = Vector3.new(vec.X,-vec.Y,vec.Z)
		if debugging == true then
			workspace.debug2.Position = vec + script.Parent["Left Arm"].Position
			print(vec)
		else
			workspace.debug2.Transparency = 1
		end
		local cf = script.Parent.Torso.CFrame:ToObjectSpace(CFrame.lookAt(script.Parent.Torso.Position, vec + script.Parent["Left Arm"].Position))
		script.Parent.Torso["Left Shoulder"].C0 = lshc * cf
		local vec = (target.Position - script.Parent["Right Arm"].Position)
		vec = Vector3.new(vec.X,-vec.Y,vec.Z)
		if debugging == true then
			workspace.debug3.Position = vec + script.Parent["Right Arm"].Position
			print(vec)
		else
			workspace.debug3.Transparency = 1
		end
		local cf = script.Parent.Torso.CFrame:ToObjectSpace(CFrame.lookAt(script.Parent.Torso.Position, vec + script.Parent["Right Arm"].Position))
		script.Parent.Torso["Right Shoulder"].C0 = rshc * cf
	else
		if script.Target.Value == nil then
			script.Parent.HumanoidRootPart["Root Hip"].C1 = c1
			script.Parent.Torso.Neck.C0 = neckc1
		end
	end
end
while wait() do
	forloop()
end