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

attempt to index field '?' (a nil value) help?

Asked by 5 years ago

How can i fix this -> 03:48:12.854 - Workspace.marobskoco.Helper.AI.Pathfinding:50: attempt to index field '?' (a nil value)

wait(2)

local PathfindingService = game:GetService("PathfindingService")

-- Variables for the zombie, its humanoid, and destination
local zombie = script.Parent.Parent
local humanoid = zombie:WaitForChild("Humanoid")
local destination = script.Parent.Parent.Parent
local olddestination

local path = PathfindingService:CreatePath()

local waypoints
local currentWaypointIndex


local function NewPath(Path)

    olddestination = destination.Head.Position

    path:ComputeAsync(zombie.HumanoidRootPart.Position, Path.PrimaryPart.Position)
    -- Empty waypoints table after each new path computation
    waypoints = {}

    waypoints = path:GetWaypoints()

    -- Move to first waypoint
    currentWaypointIndex = 1


end

NewPath(destination)

while true do

    local zombiehead = zombie.Head.Position
    local master = destination.Head.Position
    local distance = (master - zombiehead).magnitude
    local hm = destination.Humanoid
    local max_distance = 7
    local lift1 = game.Workspace.Lifts.Lift1.Lift.Position
    local lift2 = game.Workspace.Lifts.Lift2.Lift.Position

    if distance > max_distance then


        if waypoints then

            if waypoints == nil or currentWaypointIndex == nil or waypoints[currentWaypointIndex].Position == nil or waypoints[currentWaypointIndex] == nil or hm.Jump == true then
                NewPath(destination)
            end

            local one = (lift1 - master).magnitude
            local two = (lift2 - master).magnitude
            local max = 35

            if one and two > max then

                humanoid:MoveTo(waypoints[currentWaypointIndex].Position)

                if humanoid.MoveToFinished:wait() then
                    currentWaypointIndex = currentWaypointIndex + 1
--              humanoid.MoveToFinished:wait()
                else 
                    humanoid.Jump = true
                    NewPath(destination)
                end
                adistance = (master - olddestination).magnitude

                if adistance > 3 then
                    NewPath(destination)
                end

            end

        end


    end

    wait()
end
0
Position is never nil. It's a Vector3. DeceptiveCaster 3761 — 5y
0
even if i get the position = nil out off that line i get the same error some times. not every time but some times. like he cant find the path at that moment. that why i put there if they are nil start over User#27824 0 — 5y
0
what is the ? in the error? User#27824 0 — 5y

Answer this question