Pathfinding Issue, NPC refusing to walk path?
Greetings, Thanks for taking a look into my issue.
I made a pathfinding script in which I told an NPC to follow a path. (called Jake)
The path gets correctly created and I made it so a line shows how the path goes.
It's just that Jake refuses to follow the line and walks off on his own.
Here is the code, Any help is appriciated
01 | path = game:GetService( "PathfindingService" ):FindPathAsync(game.Workspace.Pathfinding.Start.Position, game.Workspace.Pathfinding.Finish.Position) |
02 | waypoints = path:GetWaypoints() |
04 | for i = 2 , #waypoints do |
05 | local lastWaypoint = waypoints [ i- 1 ] |
06 | local currentWaypoint = waypoints [ i ] |
07 | print (currentWaypoint) |
09 | local segment = Instance.new( "LineHandleAdornment" ) |
10 | local lastPosition = lastWaypoint.Position + Vector 3. new( 0 , 0.5 , 0 ) - game.Workspace.Pathfinding.Start.Position |
11 | local currentPosition = currentWaypoint.Position + Vector 3. new( 0 , 0.5 , 0 ) - game.Workspace.Pathfinding.Start.Position |
12 | local toCurrent = currentPosition - lastPosition |
13 | local distance = toCurrent.Magnitude |
15 | segment.CFrame = CFrame.new(lastPosition, currentPosition) |
16 | segment.Parent = game.Workspace.Pathfinding.Start |
17 | segment.Adornee = game.Workspace.Pathfinding.Start |
18 | segment.Thickness = 10 |
19 | segment.Length = distance |
22 | script.Parent:MoveTo(toCurrent) |
25 | local waypointType = currentWaypoint.Action |
26 | if waypointType = = Enum.PathWaypointAction.Jump then |
27 | segment.Color 3 = Color 3. new( 1 , 1 , 0 ) |
29 | segment.Color 3 = Color 3. new( 0 , 1 , 0 ) |