Pathfinding problem

Whenever pathfinding choses 4th point it just breaks and i dont know why
the pathfinding code

function Pathfinding(To)
	local Pathfind = pathfindingService:CreatePath({AgentRadius = 5,AgentHeight = 2,AgentCanJump = false,})
	Pathfind:ComputeAsync(body.Position, To)
	local waypoints = Pathfind:GetWaypoints()
	if Debug.Value == true then
		print(waypoints)
		for i,v in pairs(waypoints) do
			local Sphere = Instance.new("Part",workspace)
			Sphere.Size = Vector3.new(.6,.6,.6)
			Sphere.Anchored = true
			Sphere.CanCollide = false
			Sphere.Material = Enum.Material.Neon
			Sphere.Shape = Enum.PartType.Ball
			Sphere.Position = v.Position
			game.TweenService:Create(Sphere,TweenInfo.new(7,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{Size = Vector3.new(0,0,0)}):Play()
			game.Debris:AddItem(Sphere,7)
		end
	end
	for k, waypoint in pairs(waypoints) do
		humanoid:MoveTo(waypoint.Position)
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		humanoid.MoveToFinished:Wait()
	end
	Moving = false
end

output after 4th

{}
1 Like

I’ve added error handling using pcall to catch any potential errors that might occur during pathfinding. If an error occurs, it will be printed to the console, and the function will exit early.

function Pathfinding(To)
    local Pathfind = pathfindingService:CreatePath({
        AgentRadius = 5,
        AgentHeight = 2,
        AgentCanJump = false,
    })
    
    local success, result = pcall(function()
        Pathfind:ComputeAsync(body.Position, To)
    end)
    
    if not success then
        print("Error occurred during pathfinding:", result)
        return
    end
    
    local waypoints = Pathfind:GetWaypoints()
    
    if Debug.Value == true then
        print("Waypoints:", waypoints)
        
        for i, v in pairs(waypoints) do
            local Sphere = Instance.new("Part", workspace)
            Sphere.Size = Vector3.new(0.6, 0.6, 0.6)
            Sphere.Anchored = true
            Sphere.CanCollide = false
            Sphere.Material = Enum.Material.Neon
            Sphere.Shape = Enum.PartType.Ball
            Sphere.Position = v.Position
            game.TweenService:Create(Sphere, TweenInfo.new(7, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {Size = Vector3.new(0, 0, 0)}):Play()
            game.Debris:AddItem(Sphere, 7)
        end
    end
    
    for k, waypoint in pairs(waypoints) do
        humanoid:MoveTo(waypoint.Position)
        
        if waypoint.Action == Enum.PathWaypointAction.Jump then
            humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
        end
        
        humanoid.MoveToFinished:Wait()
    end
    
    Moving = false
end

the last output was

Waypoints:  ▼  {
                    [1] = {-121.247009, 86, 183.012863}, Walk, Fabric,
                    [2] = {-121.810486, 86, 186.972977}, Walk, Fabric,
                    [3] = {-122.373955, 86, 190.93309}, Walk, Fabric,
                    [4] = {-122.937431, 86, 194.893204}, Walk, Fabric,
                    [5] = {-123.5009, 86, 198.853317}, Walk, Fabric,
                    [6] = {-124.064377, 86, 202.813431}, Walk, Marble,
                    [7] = {-124.627846, 86, 206.773544}, Walk, Marble,
                    [8] = {-125.191322, 86, 210.733658}, Walk, Marble,
                    [9] = {-125.399963, 86, 212.200012}, Walk, Marble
                 }  -  Server - Ai1:56
  14:23:35.537  Waypoints: {}  -  Server - Ai1:56 -- this is where he tries to go on 4th waypoint
  14:23:41.036  Waypoints: {}  -  Server - Ai1:56
  14:23:46.536  Waypoints: {}  -  Server - Ai1:56

but no errors happened

few potential reasons for this issue:

Insufficient space: Ensure that there is enough space for the character to navigate from the fourth waypoint to the target point. If there are obstacles or narrow passages in that area, the pathfinding algorithm may struggle to find a valid path.

Invalid target point: Double-check that the To parameter is a valid position in the game world. If the target point is unreachable or incorrectly specified, the pathfinding algorithm may fail to generate waypoints beyond the fourth point.

i just changed the floor and he went for the 4th but it stopped working for 6th

  1. Check the area between the fifth and sixth waypoints for obstacles or narrow passages that might hinder the character’s movement. Ensure there is enough space and a clear path for the character to reach the sixth waypoint.

  2. Adjust the AgentRadius and AgentHeight parameters in the pathfindingService:CreatePath function to accurately represent the character’s dimensions. This will help the pathfinding algorithm navigate through tight spaces more effectively.

  3. Consider implementing a custom pathfinding algorithm or exploring alternative pathfinding libraries or approaches if the default algorithm provided by pathfindingService is not producing satisfactory results. This can offer more control and flexibility in complex environments.

  4. Simplify the environment temporarily by removing unnecessary obstacles or complex elements. This will help determine if the issue is caused by the environment’s complexity or specific obstacles.

Thats all i can think of

Theres none only corners

They’re already adjusted

not sure how