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