Help with Pathfinding waypoints?

local oldpart = script.Parent.Parent:FindFirstChild(script.Parent.Name..'Dest')
			local path = pathfind:CreatePath()
			path:ComputeAsync(script.Parent.HumanoidRootPart.Position, dest)

			local wps = path:GetWaypoints()
			local destwp = #wps
			path.Blocked:Connect(function(waypoint)
			wps[waypoint].Position = wps[waypoint].Position + Vector3.new(math.random(1,5),0,Vector3.new(math.random(1,5)))
			end)
			local lastwp = wps[destwp]
			if oldlist == nil then
				oldlist = wps
			elseif oldlist ~= nil then
				oldlist:Destroy()
				oldlist = wps
			end



			if oldpart ~= nil then
				oldpart.Position = lastwp.Position
				hum.WalkToPoint = oldpart.Position
				repeat wait() until (hrp.Position - oldpart.Position).Magnitude <= 10
			elseif oldpart == nil then
				local part = Instance.new("Part")
				part.Parent = script.Parent.Parent
				part.Name = script.Parent.Name..'Dest'
				part.Transparency = 1
				part.CanCollide = false
				part.Anchored = true
				part.Position = lastwp.Position
				hum.WalkToPoint = part.Position
				repeat wait() until (hrp.Position - part.Position).Magnitude <= 10 or script.Parent:GetAttribute('Stage') == 'Triggered'
			end

So this is the script. However, apparently lastwp is nil.
The error is Attempt to index nil with Position.

Try printing wps and #wps. If for whatever reason the length of the table is 0 or it’s a dictionary, it’s going to return nil.

Already tried. It returns zero. But I don’t know why. :pensive:

Try printing path.Status maybe? Also a screenshot of the path would be helpful.

Oki doki. I’ll try the print thing. o7

1 Like

Oh shoot, I meant path.Status, not path.PathStatus. PathStatus is the enum index.

1 Like

Oh my. It says no path. :C How do I fix that?

I had this exact issue a few days ago. Try this out:

1 Like

I am a bit confused though. Why would a human in the workspace break the entire path?

I’m not sure to be honest.

I know that having a lot of parts in the workspace and then adding a humanoid will slightly offset them so I’m guessing floating point errors. If not floating point errors then probably something to do with collision.

1 Like