Me and my friend are trying to make AI move for a game, but we can’t get it to work.
local PFS = game:GetService("PathfindingService")
local paths = {}
local constraints = {}
local objects = script.Objects:GetDescendants()
for i,v in pairs(script.Constraints:GetDescendants()) do
local path = PFS:CreatePath()
constraints[#constraints + 1] = v
path:ComputeAsync(v.Attachment0.Parent.Position, v.Attachemt1.Parent.Position)
paths[#paths + 1] = path
--constraints[#constraints + 1] = v
end
for i,v in pairs(objects) do
v:Destroy()
end
while true do
spawn(function()
local clone = game.ServerStorage["Bob the worker"]:Clone()
clone.Parent = workspace
local random = math.random(1,#paths)
local path_chosen = paths[random]
clone:MoveTo(constraints[random].Attatchment0.Parent.Position)
for i,v in pairs(path_chosen:GetWaypoints()) do
clone.Humanoid.MoveTo(v.Position)
clone.Humanoid.MoveToFinished:Wait()
end
task.wait(5)
clone:Destroy()
end)
task.wait(1)
end
What are we doing wrong?