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
.