Issues with 'NPC to Face Character when Talking'

What I want to Achieve: When a player comes across an NPC and talks to the NPC that is moving in the map, I want the NPC to ‘face’ the character who triggered it.

My code halfway works right, but there sometimes, I feel like orientation might not be the best way to go. I’m open to suggestions.

I haven’t found anything on the Dev Forum that can help!

function onClicked(player)
	local char = player.Character
	local characterModelServer = game.Workspace:WaitForChild(char.Name)
	local npcModelServer = game.Workspace.NPCS:WaitForChild("Matt")
	local charOrientationYS = characterModelServer.HumanoidRootPart.Orientation.Y
	local npcXS = npcModelServer.HumanoidRootPart.Orientation.X
	local npxZS = npcModelServer.HumanoidRootPart.Orientation.Z
	npcModelServer.Humanoid.WalkSpeed = 0
		npcModelServer.HumanoidRootPart.Orientation = Vector3.new(npcXS, -charOrientationYS, npxZS)
end

game.ReplicatedStorage.NPCEvents.StopNPC.OnServerEvent:Connect(onClicked)

1 Like

You could use CFrame.new ( Vector3 pos, Vector3 lookAt ).

1 Like