Hello. I am trying to use PathfindingService to create a path for an NPC to walk when a player touches a part. At line 45 of the code (the one that says for _, in pairs()) , the for loop doesn't run. I think that's the case since the print() statement at line 47 wasn't printed.
the script goes like so: when the player steps on "activate", the function(OnPartTouched) will run.
i've included which statements have been printed. this script is in starter character scripts and its a local script.
any idea why for in pairs() loop isn't running?
any help is appreciated!
my code is pasted below.
01 | local PathFindingService = game:GetService( "PathfindingService" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 |
04 | local T 1 NPC 1 = game.Workspace.T 1 NPC [ "1" ] .T 1 NPC 1 |
05 | local NPCHumanoid = T 1 NPC 1. Humanoid |
06 | local Activate = game.Workspace.T 1 NPC [ "1" ] .Activate |
07 |
08 |
09 | local path = PathFindingService:CreatePath() |
10 |
11 | local CanMakePath = true |
12 |
13 | local function OnPartTouched(hit) |
14 |
15 | if CanMakePath = = true then |
if PathfindingService isn't able to find a valid path between the starting and ending point, or if there's something intersecting the starting point or ending point, it won't create any waypoints
it's probably caused by the ending point being 2.5 studs below the player ((which is literally right next to the ground))
also, there's no reason to create a new part just to get its position, you can just use the HumanoidRootPart's position directly
also also, even if PathfindingService was able to create the waypoints, unless the client has network ownership over the npc for some reason or the npc was created on the client, they wouldn't be able to move it, so you'd have to move this to the server anyway
hey elyzzia, could you take a look at the comments below your answer? thx for your time and help