i’m trying to make a script handle the pathfinding of every npc in a folder. there are 3 models in this folder. however, it only makes one model pathfind, which is odd.
local pathfinding_service = game:GetService("PathfindingService")
local collection_service = game:GetService("CollectionService")
local run_service = game:GetService("RunService")
local path
local waypoints
local personoid
local test_part = workspace:WaitForChild("test_part")
local tripmines = workspace:WaitForChild("tripmine_folder"):GetChildren()
path = pathfinding_service:CreatePath({
AgentRadius = 2,
AgentHeight = 1.2,
Costs = {
Water = 20,
subspace = math.huge
}
})
run_service.Heartbeat:Connect(function()
for i, tripmine in ipairs(tripmines) do
if tripmine:IsA("Model") then
local hostile_part = tripmine.PrimaryPart
if not hostile_part then
warn(`PrimaryPart not found for {tripmine}`)
else
path:ComputeAsync(hostile_part.Position, test_part.Position)
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
for i, waypoint in ipairs(waypoints) do
local part = Instance.new("Part")
part.Name = (`waypoint_{i}`)
part.Anchored = true
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Material = Enum.Material.Neon
part.Shape = Enum.PartType.Ball
part.CanCollide = false
part.Parent = workspace.Terrain
part.Position = waypoint.Position
game:GetService("Debris"):AddItem(part, 0.1)
--[[
if tripmine:FindFirstChildWhichIsA("Humanoid") then
personoid = tripmine:FindFirstChildWhichIsA("Humanoid")
personoid:MoveTo(waypoint.Position)
personoid.MoveToFinished:Wait()
end
]]
end
end
end
end
end
end)