Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help with how to make npcs, I've never done it before?

how would I make a npc that moves and that can follow people around?

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.

1 comment

0

Put this inside the NPC model as a script

This discussion is preserved as it was. New answers, comments, and votes are closed.