Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

pathfinding not finding a path for some reason?

when i spawn it waits a second to let the character spawn and then after that second it immediately prints no path ;/

wait(1)
local plr = game.Players.LocalPlayer
local char = plr.Character

local pathfind = game:GetService("PathfindingService")

local p1 = pathfind:FindPathAsync(char.LowerTorso.Position,workspace.ptgt.Position)

if p1.Status == Enum.PathStatus.Success then
	for i,v in pairs(p1:GetWaypoints())do
		char.Humanoid:MoveTo(v)
		char.MoveToFinished:Wait()
		if v.Action == Enum.PathWaypointAction.Jump then
			char.Humanoid.Jump = true
		end
	end
else print "no path"
end

output: no path

(it is a local script)

1 answer

✓ Accepted answer

Your script will only run once so what you need to do is put the pathfinding script inside a while loop like this

wait(1)
local plr = game.Players.LocalPlayer
local char = plr.Character

while wait(1) do -- it will create a new path every 1 second, you can change it
local pathfind = game:GetService("PathfindingService")

local p1 = pathfind:FindPathAsync(char.LowerTorso.Position,workspace.ptgt.Position)

if p1.Status == Enum.PathStatus.Success then
    for i,v in pairs(p1:GetWaypoints())do
        char.Humanoid:MoveTo(v)
        char.MoveToFinished:Wait()
        if v.Action == Enum.PathWaypointAction.Jump then
            char.Humanoid.Jump = true
        end
    end
else print "no path"
end
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.

1 comment

0

this is not actually the problem, the gap between a couple walls in the maze i was walking through was too small, thus stopping the path from being fully created, thanks for the help though!

This discussion is preserved as it was. New answers, comments, and votes are closed.