Hi there, i know using infinite while () loops isn't a good idea but I'm not sure how else I'd go about doing this with the desired effect?
Script:
while wait() do
local distance = 10
for _, v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Model") and v.Name ~= "Dummy" then
for _, npc in pairs (NPCs:GetChildren()) do
if npc:IsA("Model") and npc:FindFirstChild("Humanoid").Health > 0 then
local humanRP = v:WaitForChild("HumanoidRootPart")
if (npc.HumanoidRootPart.Position - humanRP.Position).magnitude < distance then
npc.Humanoid:MoveTo(humanRP.Position)
end
end
end
end
end
end
Thanks,

3 comments
What is this trying to do?
It's an NPC that chases the player if they are within the "distance"
Using events can sometimes be a great replacement for loops.