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

How do you make the npcs head folow the player?

Asked by 2 years ago

IN cook burgers here The npcs head always follows the player i thought it looked cool how do I do it thought?

0
Try using pathfinding services or something similar Xyternal 247 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

function findTorso(pos) local torso = nil local dist = 100000 local child = workspace:children() for i=1, #child do if child[i].className == "Model" then local h = child[i]:findFirstChild("Humanoid") if h ~= nil then local check = child[i]:findFirstChild("Head") if check ~= nil then if (check.Position - pos).magnitude < dist then torso = check dist = (check.Position - pos).magnitude end end end end end return torso end

game:GetService("RunService").Stepped:Connect(function() local torso = findTorso(script.Parent.Position) if torso ~= nil then script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position) end end)

Put this script in the Head of the NPCs and make it sure its anchored or the head will just come after the player.

Ad

Answer this question