[Solved] Path Blocked Detection PathFinding

So what you are looking for, is something like:

  • Waiting less than the hard-coded 8 seconds (How much less? Max 3 seconds?)
  • Or when MoveToFinished is fired, as long it happens before the “waiting less than”

Perhaps using a BindableEvent can be a work-around? One that will be fired by a MoveToFinished:Connect() or a “waiting less than 8 seconds”-delayed-function.

The below code has not been tested, so I do not know if it actually works or not! :face_with_raised_eyebrow:

local function moveNPC(plrHum, pathObject)
	local pathTable = pathObject:GetWaypoints()
	for i, point in pairs(pathTable) do
		if point.Action == Enum.PathWaypointAction.Jump then
			plrHum:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		
		local evt = Instance.new("BindableEvent")
		delay(3, function() if evt then evt:Fire("Timeout") end end)
		plrHum.MoveToFinished:Connect(function() if evt then evt:Fire("Finished") end end)
		
		plrHum:MoveTo(point.Position)
		
		local result = evt.Event:Wait()
		evt:Destroy() -- Important to "clean up"
		evt = nil -- Equally important, for attempting to not cause the anonymous functions error
		
		if result == "Timeout" then
			return {status = 0}
		end
	end

	return {status = 1}
end
6 Likes