how would I make a npc that moves and that can follow people around?
✓ ANSWER ACCEPTED
Can someone help with how to make npcs, I've never done it before?
1 answer
✓ Accepted answer
Some simple research or searching in the toolbox can solve your problem.
local PositionTorso = script.Parent.Torso.Position
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = math.huge
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("UpperTorso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
end
end
end
end
return torso
end
while wait(0.15) do
local target = findNearestTorso(PositionTorso)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position)
end
end
This script does find the nearest torso and moves towards it every 0.15 seconds if it exists.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Put this inside the NPC model as a script