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

How to make the table keep updating with the positions?

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

1 answer

Since you're using the MoveTo() method for humanoids, you could just insert a reference the Torso part of the players into the table.

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