ROBLOX NPC: How to make it turn the player's way

I want to figure out how to make it so when I click on my NPC’s torso to talk to them, they turn my way. It would add a nice level of interactivity. Here’s my script:

local torso = script.Parent.Torso
torso.ClickDetector.MouseClick:Connect(function(player)
local chat = game.ServerStorage.Objects.GUI.ChatGui.EmmilinChatGui:Clone()
chat.Parent = player.PlayerGui
script.Parent.Humanoid.WalkSpeed = 0
player.Character.Humanoid.WalkSpeed = 0
wait(30)
script.Parent.Humanoid.WalkSpeed = 10

end)

Any help is greatly appreciated! :hugs:

By making a part face another part you can use:

NpcsTorso.CFrame = CFrame.new(NpcsTorso.Position, PlayersTorso.Position)
1 Like

I don’t know what variables you have in store but you will have to change those.

So something like this:

torso.CFrame = CFrame.new(torso.Position, player.Character.Torso.Position)

Yup! That should work fine. Otherwise lmk.

Thank you so much! It actually works!

1 Like

This is correct, but just one note to prevent the Npc from falling over.

local from = NpcsTorso.Position
local too = PlayersTorso.Position
local pointDirection = (too-from) * Vector3.new(1,0,1)
NpcsTorso.CFrame = CFrame.new(from, from + pointDirection)

With the existing code - if the player is above or below the NPC - the NPC will look up/down and fall over as a result.

The correction above sets the Y (up/down) value relative to the NPC’s Y position. This means its always pointing level with the NPC and won’t fall over.

2 Likes

You could just anchor it and unanchor it as well.

Use CFrame.lookAt() the one you’re doing is deprecated.

There are multiple approaches to this.

Thank you for your help @libriumdev, but I found that this method works perfectly!

I’m just saying this in case you encounter the same issue in the future, for example, you shouldn’t use Humanoid:LoadAnimation() but Animator:LoadAnimation(). Since it’s deprecated, Roblox will care more about it’s replacement.