You can definitely create an NPC using just module scripts, and you can use the method I was talking about too.
e.g. same local script:
local npc = -- your npc
and the npc’s
RunScript (which is still a module script):
local Players = game:GetService("Players")
local NPC = script.Parent
local humanoid = NPC:WaitForChild("Humanoid")
local function getNearestTarget()
-- I don't feel like writing that,
-- but it returns the nearest player
-- this is wrapped in a coroutine so that it doesn't yield forever.
local followLoop = task.defer(function()
while true do
local target = getNearestTarget()
local targetRoot = target.Character.HumanoidRootPart
-- tell the humanoid to stop moving
humanoid:Move(Vector3.new(0, 0, 0))
The first time you require the
RunScript module is the moment all this code gets executed.
There are other ways to structure the module if you don’t like doing it like this, like putting all this code in some functions in a table and returning the table so that the local script can run all the logic.