Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make NPC looking at player?

Asked by 6 years ago

How to make NPC looking at player.

1 answer

Log in to vote
0
Answered by
zyrun 168
6 years ago

Well, I'm not quite sure what you're asking, but assuming you want a Player-Like NPC to look at a player your code should be a Server Script in the NPC and will look like this:

local NpcPart = script.Parent:WaitForChild("HumanoidRootPart") -- You can change this to any part if your NPC isn't a Player-Like NPC
local PlayerToLookAt = game.Workspace:WaitForChild("ThiagoGamestar").HumanoidRootPart

NpcPart.CFrame = CFrame.new(Vector3.new(NpcPart.Position), Vector3.new(PlayerToLookAt))
-- The Cframe is CFrame.new(The Position you want the NPC to be in, The Position you want the NPC to be looking at 

-- IF you want the NPC to constantly to be looking at the player, use this code instead:

local NpcPart = script.Parent:WaitForChild("HumanoidRootPart") 
local PlayerToLookAt = game.Workspace:WaitForChild("ThiagoGamestar").HumanoidRootPart

while true do
NpcPart.CFrame = CFrame.new(Vector3.new(NpcPart.Position), Vector3.new(PlayerToLookAt))
wait(0) -- 0 is how long it will wait until the NPC adjusts to look at the player again. (make sure it is at least a 0) 
end
0
Why my NPC is disappearing? ThiagoGamestar 11 — 5y
Ad

Answer this question