Getting NPC to face player when interacting

Hello, I have this code here: (it runs on a script with runcontext set to client)

local npc = script.Parent.Parent

npc:WaitForChild("Prompt").TalkPrompt.Triggered:Connect(function(plr)
	local chara = plr.Character
	npc.HumanoidRootPart.RootJoint.C0 = CFrame.lookAt(npc.HumanoidRootPart.RootJoint.C0.Position, chara.Head.Position)
end)

It’s meant to face the player when the NPC is interacting.

However, that isn’t the case: (ignore proximity prompt ill fix that later)


They face the same direction every time the player interacts with them.

Try setting the actual humanoidrootpart of the npc to face the player

local npc = script.Parent.Parent

npc:WaitForChild("Prompt").TalkPrompt.Triggered:Connect(function(plr)
	local chara = plr.Character
	npc.HumanoidRootPart.CFrame = CFrame.lookAt(npc.HumanoidRootPart.Position, chara.HumanoidRootPart.Position)
end)

The NPC ended up teleporting to the null point with the changes

local lookAtPos = Vector3.new(chara.HumanoidRootPart.Position.X, npc.HumanoidRootPart.Position.Y, chara.HumanoidRootPart.Position.Z)
npc.HumanoidRootPart.CFrame = CFrame.lookAt(npc.HumanoidRootPart.Position, lookAtPos)

try this, if you want the npc to constantly face the player, you need a loop

Instead of having a loop, I’d recommend having a trigger (like whenever the player enters the NPC’s area). And disconnect the event whenever the player gets out of the NPC’s Area. This is to gain performance and avoid memory leaks :wink:

Does the same effect to the player but saves performance :wink: