Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm confused, My bot Ai suddenly stopped working, any help?

Asked by 3 years ago

Hi,

I've made a bot that wonders around to set locations and then the other day (even though I did nothing to the script) it keeps coming up with the following output error and I can't figure out why. For some reason it's unable to calculate a path?

Here's the script I have:

local PathfindingService = game:GetService("PathfindingService")

-- Variables for the zombie, its humanoid, and destination
local zombie = script.Parent
local humanoid = zombie.Humanoid
local locfolder = script.Parent.Parent.OPoints
--local count
local continuee
local destination 

-- Create the path object
local path = PathfindingService:CreatePath()

-- Variables to store waypoints table and zombie's current waypoint
local waypoints
local currentWaypointIndex

local function followPath(destinationObject)
    print("follow path recieved")
    script.Parent.PrimaryPart:SetNetworkOwner(nil)
    -- Compute and check the path
    path:ComputeAsync(zombie.HumanoidRootPart.Position, destinationObject.Position)
    -- Empty waypoints table after each new path computation
    waypoints = {}

    if path.Status == Enum.PathStatus.Success then
        print("Success calc")
        -- Get the path waypoints and start zombie walking
        waypoints = path:GetWaypoints()
        -- Move to first waypoint
        currentWaypointIndex = 1
        humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
    else
        print("Error calculating")
        -- Error (path not found); stop humanoid
        humanoid:MoveTo(zombie.HumanoidRootPart.Position)
    end
end

local function onWaypointReached(reached)
    print("Waypoint reached")
    if reached and currentWaypointIndex < #waypoints then -- this is the line that the error appears from
        currentWaypointIndex = currentWaypointIndex + 1
        humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
    elseif reached and currentWaypointIndex == #waypoints then
        continuee = true
        --wait(5)
    end
end

local function onPathBlocked(blockedWaypointIndex)
    print("Path Blocked")
    -- Check if the obstacle is further down the path
    if blockedWaypointIndex > currentWaypointIndex then
        -- Call function to re-compute the path
        continuee = true
        --wait(5)
        followPath(destination)
    end
end

-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)

-- Connect 'MoveToFinished' event to the 'onWaypointReached' function
humanoid.MoveToFinished:Connect(onWaypointReached)

--followPath(destination)
--local function 


--wait(30)
while true do
    --wait(5)
    --wait(15)
    continuee = false
    print("Follow Path Sent")
    locfolderLength = locfolder:GetChildren()
    for i = 1, #locfolderLength do
        print(i)
        destination = locfolder[i]
        followPath(destination)
        repeat wait() until continuee == true
        continuee = false
        wait(2)
    end
end

and Here's the output after running for about 30 seconds:

  12:29:34.937  Follow Path Sent  -  Server - OBot:77
  12:29:34.937  1  -  Server - OBot:80
  12:29:34.938  follow path recieved  -  Server - OBot:19
  12:29:54.994  Error calculating  -  Server - OBot:34
  12:29:54.999  Waypoint reached  -  Server - OBot:41
  12:29:54.999  Workspace.Rig.Ophelia.OBot:42: attempt to compare nil < number  -  Server - OBot:42
  12:29:54.999  Stack Begin  -  Studio
  12:29:54.999  Script 'Workspace.Rig.Ophelia.OBot', Line 42 - function onWaypointReached  -  Studio - OBot:42
  12:29:55.000  Stack End  -  Studio

I'm completely stumped. Any suggestions on how to fix this will be highly appreciated.

Thanks, Aidan

1 answer

Log in to vote
0
Answered by 3 years ago

For anyone wondering, there was an issue with some other seemingly random script that caused this not to work. Now just trying to figure out a new way to make that other script work...

Ad

Answer this question