This script is supposed to make an NPC follow the nearest player. The script works, but I want the values to keep updating, so how would I do that?
person = {}
positions = {}
wait(1)
for i,v in pairs(game.Players:GetChildren())do
table.insert(person, v.Character.HumanoidRootPart.Position)
end
while wait(0.1)do
for i = 1, #person do
local mag = (person[i] - script.Parent.Torso.Position).magnitude
table.insert(positions, mag)
table.sort(positions)
script.Parent.Humanoid:MoveTo(person[1])
end
end
