How does PathFindingService work?

function MakePath(startposition, endposition)
	local Path:Path -- is path the name of the variable? what does the ":Path" do at the end of the variable?
	
	Path = PathfindingService:CreatePath() -- i think this makes the Path variable into a Path instance?
	Path:ComputeAsync(startposition, endposition) -- function for Path instances which contains where the NPC should walk to reach the goal
	
	if Path.Status == Enum.PathStatus.Success then -- if the NPC reaches the goal
		return Path
	else
		repeat task.wait(0.1) until Path.Status == Enum.PathStatus.Success -- wait until the NPC reaches the goal
	end
	
end

function WalkZombie(Humanoid, startposition, endposition)
	local Path = MakePath(startposition, endposition)
	
	local WayPoints = Path:GetWaypoints() -- function which returns a table of positions the NPC should walk to in order to reach the goal
	local CurrentWayPoint = 1 -- waypoint the NPC is walking on
	
	local FinishedConnection:RBXScriptConnection -- i have absolutely no clue what this is
end

So I just followed a tutorial on PathFindingService the other day, and they use some terms which are fairly confusing for me. Please note that what I have above is only a very small piece of the script, I just included the things that I am confused about.

I left comments on each line I related to PathFindingService, if anyone could explain the pieces I don’t know, and confirm the pieces I left comments on, that would be extremely helpful

1 Like

Also another issue, the NPC will stop for a short period of time between points, instead of walking smoothly from point to point. Is this normal?

The : Path in the path variable is the type annotation for the Path type. PathfindingService:CreatePath() creates a new Path object, in this case it’s assigned to the Path variable. : RBXScriptConnection is also a type annoation. Apologies if this response is a bit lackluster. I suck at explaining things. You should read up on types and type-checking in Luau to get a better grasp on this.