hello ive been trying to do a function that automatically choose a waypoints that is not being chosen before and make an npc walk there, however i dont know how to make it so that it would not repeat a used waypoint.
local unit = script.Parent
local waypoints = workspace.Map.Control_Centre:GetChildren()
ReplicatedStorage = game:GetService("ReplicatedStorage")
NewDefender = ReplicatedStorage.Events:WaitForChild("NewDefender")
local function SpawnNewDefender()
local notused = {}
for points in pairs(notused) do
notused[points] = nil
end
for waypoint in pairs(waypoints) do
if waypoints[waypoint].Used.Value == false then
table.insert(notused, waypoint)
end
end
local gowaypoint = math.random(1,#notused)
print(waypoints[gowaypoint])
if waypoints[gowaypoint].Used.Value == false then
unit.Humanoid:MoveTo(waypoints[gowaypoint].Position)
unit.Humanoid.MoveToFinished:Wait()
unit.Humanoid:MoveTo(waypoints[gowaypoint].Stand.Position)
waypoints[gowaypoint].Used.Value = true
end
end
NewDefender.Event:Connect(SpawnNewDefender)