Pathfinding isn't working

So I’m making a school game with teachers as NPCs. This pathfinding won’t work and I’m very confused.


It’s supposed to go in the school, which is where the destination part I have is, but it gets stuck around here.

I checked through the rest of the code such as the variables used in the following. Nothing wrong. I’m pretty sure I made a mistake in the pathfinding section of my script but I’m not sure where.

local Destination = PathfindingDestinations.MathClass.Position
		local Path = PathfindingService:CreatePath()
		Path:ComputeAsync(TeacherNPC:FindFirstChild("HumanoidRootPart").Position or TeacherNPC:FindFirstChild("Torso"), Destination)
		local Waypoints = Path:GetWaypoints()
		local NPCHumanoid = TeacherNPC.Humanoid
		
		for k, Waypoint in pairs(Waypoints) do
		    NPCHumanoid:MoveTo(Waypoint.Position)
		    if Waypoint.Action == Enum.PathWaypointAction.Jump then --Make NPC jump if needed.
		        NPCHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		    end
		    NPCHumanoid.MoveToFinished:Wait()
		end

you forgot to include .Position but this is unnecessary because both R15 and R6 has a HumanoidRootPart.

TeacherNPC:FindFirstChild("Torso").Position


have you done any research before asking for help?

There are resources available on the DevHub:

there’s a lot of potential errors with your code which all are addressed in the links above

1 Like

I recommend using a pcall. This wont break your script, but will tell you if the path is possible, or if theres something in the way.