Making NPCs Smarter

So i made this script that basically tells an NPC to go to a certain location using PathFindingService:

local service = game:GetService("PathfindingService")


local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

local path = service:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.endp.Position)
local waypoints = path:GetWaypoints()

for i, waypoint in pairs(waypoints) do
	local part ="Part")
	part.Shape = "Ball"
	part.Material = "Neon"
	part.Size =,0.5,0.5)
	part.Position = waypoint.Position +,2,0)
	part.Anchored = true
	part.CanCollide = false
	part.Parent = game.Workspace
	if waypoint.Action == Enum.PathWaypointAction.Jump then


Very simple script. It does in fact work like in the gif below, but i often find myself in a common situation, NPCs will just face walls and wait for them to be able to pass through (I have a script that makes some parts appear and disappear to test the NPCs “brain”)

So i was wondering how i could use the .Blocked function when NPCs find themselves in a situation where the path is blocked and they need to figure out what to do.

Any help is appreciated and thanks!

Roblox explains this pretty well, if i’m not mistaken and list how to use the api in this post

1 Like

I’ll take a look at it. Thanks

So i do see how it is but not quite understand. After the path is not Enum.PathStatus.Success, being NoPath, how do i make it so the humanoids creates a new path?