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