The AI keeps twitching.
I’m pretty sure It keeps changing its destination because of the while true do wait.
local function Follow_Path(Destination)
local Success, Data = pcall(Path.ComputeAsync, Path, PrimaryPart.Position, Destination)
if Success and Path.Status == Enum.PathStatus.Success then
WayPoints = Path:GetWaypoints()
BlockedConnection = Path.Blocked:Connect(function(BlockedWaypointIndex)
if BlockedWaypointIndex >= NextWaypointIndex then
BlockedConnection:Disconnect()
Follow_Path(Destination)
end
end)
if not ReachedConnection then
ReachedConnection = Humanoid.MoveToFinished:Connect(function(Reached)
if Reached and NextWaypointIndex < #WayPoints then
NextWaypointIndex += 1
Humanoid:MoveTo(WayPoints[NextWaypointIndex].Position)
else
ReachedConnection:Disconnect()
BlockedConnection:Disconnect()
end
end)
end
NextWaypointIndex = 2
Humanoid:MoveTo(WayPoints[NextWaypointIndex].Position)
else
warn("Path not computed!")
end
end
while true do
local WayPoints = Workspace_Roam_Parts:GetChildren()
local RandomNumber = math.random(1, #WayPoints)
local Player = Fetch_Nearest_Players()
local Destination = Player and Player.Character.PrimaryPart.CFrame.p
or WayPoints[RandomNumber].Position
Follow_Path(Destination)
end