Hey! I’m having an issue where my pathfinding AI goes from spawn to waypoint 1 smoothly, but it then proceeds to stop in-between waypoint 1 and 2 then goes toward the third waypoint. I am relatively new to pathfinding so it may as well be something very simple. Many thanks in advance for those who help!
local pathfindingService = game:GetService("PathfindingService")
local pathsetDecided = false
local movementDebounce = false
local chosenPathset = nil
local pathNumber = 0
while task.wait(0.1) do
if pathsetDecided == true and chosenPathset ~= nil then
if movementDebounce == false then
movementDebounce = true
pathNumber = pathNumber + 1
print(pathNumber)
local chosenPath = chosenPathset:FindFirstChild("waypoint"..pathNumber)
if ("waypoint"..#chosenPathset:GetChildren()) ~= chosenPath.Name then
local path = pathfindingService:CreatePath()
path:ComputeAsync(script.Parent.Parent.HumanoidRootPart.Position, chosenPath.Position)
for i, waypoint in pairs(path:GetWaypoints()) do
script.Parent.Parent.Humanoid:MoveTo(waypoint.Position)
script.Parent.Parent.Humanoid.MoveToFinished:Connect(function()
movementDebounce = false
end)
end
end
end
else
local pathChoices = game.Workspace.CivWaypoints:GetChildren()
local chosenPathNumber = math.random(1, #pathChoices)
chosenPathset = pathChoices[chosenPathNumber]
pathsetDecided = true
end
end