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

Why won't my zombie wander around the map?

Asked by 4 years ago

Hi, I am trying to make my zombie wander around the map to different "destinations" until he sees a player and attacks. I keep getting this error in the output: " 16:10:49.207 - Workspace.FireZombie3.AI:50: attempt to perform arithmetic (sub) on number and nil"

Anything will help, thank you!

Here is my code:

function findDestination()
    local Map = game.Workspace.MapHolder:WaitForChild("Map")
    local destinationsfolder = Map:WaitForChild("Destinations")
    local destinations = destinationsfolder:GetChildren()
    for i = 1,#destinations do
        if (destinations[i].Position - myRoot.Position).Magnitude <= 25 then
             oldDestination = destinations[i].Place.Value
            print(oldDestination)
        end
    end
    for i = 1,#destinations do
        if (destinations[i].Place.Value - oldDestination) == 1 then   -- This seems to be where the error occurs
        local goal = destinations[i].Position
        print(goal)
        return goal
        end
    end
end

function walkRandomly()
    local goal = findDestination()
    local path = game:GetService("PathfindingService"):CreatePath()
    path:ComputeAsync(myRoot.Position, goal)
    local waypoints = path:GetWaypoints()
    if path.Status == Enum.PathStatus.Success then
        for _, waypoint in ipairs(waypoints) do
            if waypoint.Action == Enum.PathWaypointAction.Jump then
                myHuman.Jump = true
            end
            myHuman:MoveTo(waypoint.Position)
            local timeOut = myHuman.MoveToFinished:Wait(1)
            if not timeOut then
                print("Got stuck")
                myHuman.Jump = true
                walkRandomly()
            end
        end
    else
        print("Path failed")
        wait(1)
        walkRandomly()
    end
end
0
Is it anchored? EmptyVib_es 3 — 4y
0
No it's not anchored Channy97 10 — 4y

Answer this question