when i spawn it waits a second to let the character spawn and then after that second it immediately prints no path ;/
01 | wait( 1 ) |
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character |
04 |
05 | local pathfind = game:GetService( "PathfindingService" ) |
06 |
07 | local p 1 = pathfind:FindPathAsync(char.LowerTorso.Position,workspace.ptgt.Position) |
08 |
09 | if p 1. Status = = Enum.PathStatus.Success then |
10 | for i,v in pairs (p 1 :GetWaypoints()) do |
11 | char.Humanoid:MoveTo(v) |
12 | char.MoveToFinished:Wait() |
13 | if v.Action = = Enum.PathWaypointAction.Jump then |
14 | char.Humanoid.Jump = true |
15 | end |
16 | end |
17 | else print "no path" |
18 | end |
output: no path
(it is a local script)
Your script will only run once so what you need to do is put the pathfinding script inside a while loop like this
01 | wait( 1 ) |
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character |
04 |
05 | while wait( 1 ) do -- it will create a new path every 1 second, you can change it |
06 | local pathfind = game:GetService( "PathfindingService" ) |
07 |
08 | local p 1 = pathfind:FindPathAsync(char.LowerTorso.Position,workspace.ptgt.Position) |
09 |
10 | if p 1. Status = = Enum.PathStatus.Success then |
11 | for i,v in pairs (p 1 :GetWaypoints()) do |
12 | char.Humanoid:MoveTo(v) |
13 | char.MoveToFinished:Wait() |
14 | if v.Action = = Enum.PathWaypointAction.Jump then |
15 | char.Humanoid.Jump = true |
16 | end |
17 | end |
18 | else print "no path" |
19 | end |
20 | end |
When the game runs, the script will check if there is anything nearby to move to and if there isn't, then the script will just stop since it ran only once.