R6 NPC Facing to player position is wrong

Hello!
So lately, I’ve been making a prison game like entry point which the guard suspect you on every illegal actions you make. The problem is that


It is facing in wrong direction!
Code:

	local player = getClosestPlayer()
	if player then
		local is_in_front = NPC.PrimaryPart.CFrame:ToObjectSpace(player.PrimaryPart.CFrame).Z < 0
		if is_in_front then
			local unit = -(NPC.PrimaryPart.CFrame.p - player.PrimaryPart.Position).unit
			neck.C0 = cframe0 * CFrame.new(Vector3.new(0, 0, 0), unit)* CFrame.Angles(math.rad(unit.Z), -math.rad(NPC.PrimaryPart.Orientation.Y),0) -- CFrame.lookAt(script.Parent.Head.Position,Vector3.new(player.Head.Position.X,script.Parent.Head.Position.Y,player.Head.Position.Z))

		end
	end
	wait()

Please help!

Heyo, just taking a quick look at this, seems like you got your numbers switched around, try this:

neck.C0 = cframe0 * CFrame.new(Vector3.new(0, 0, 0), unit)* CFrame.Angles(0, -math.rad(NPC.PrimaryPart.Orientation.Y),math.rad(unit.Z))
1 Like

Sorry for late reply, I was on school. Also It doesnt work. The problem is continue like the video i sended

Also I tested on the other NPC (without moon animator NPC) it seems to work properly. I think they was a problem about a weld in the NPC

It must be an issue with your Y rotation then, attachment displacement perhaps?

1 Like

Alright the problem is about the rig. I tried with both moon animator rig and the roblox default rig it seems to work on the default rig but not the moon animator rig. I think its because of the weld I THINK. Any way thanks for helping me!

2 Likes