NPC Head Bugging Out

The NPC’s in my game have localized head tracking to follow players when in-range. However, there has been a random bug occuring where the NPC’s head will fall into the NPC torso (see image below). I am not entirely sure why this is happening, my early assumption was that the joint didn’t exist early enough so I tried anchoring the heads until they need to be moved with no luck. The script below uses the default “Neck” Motor6D found in the character head.

Bug Image

Head Code

self.connections["head"] = RunService.Heartbeat:Connect(function()
		local character, root = GetLocalCharacter()

		if (not character) or (not root) then
			return
		end

		local direction = (CFrame.new(self.position,root.Position):Inverse() * self.cframe ).lookVector * -1

		if self.personality.UseYAxis then
			self.neck.C0 = CFrame.new(0, self.neck.C0.Y, 0) * CFrame.Angles(0, -math.asin(direction.x), 0) * CFrame.Angles(math.asin(direction.y), 0, 0)
		else
			self.neck.C0 = CFrame.new(0, self.neck.C0.Y, 0) * CFrame.Angles(0, -math.asin(direction.x), 0)
		end
	end)

Any help is much appreciated!

bump (character limit character limit)

Have you figured out a way to solve this yet? I do see a discrepancy in the math regarding like vectors / positioning?

I have not, if you have any ideas it would be much appreciated!

Try using welding, like BodyVelocity or something like it