PathFinding help to make straighter


so how would i make this npc follow a straighter path since i wanna make a guard patrol system.

wait(5)
local PFS = game:GetService("PathfindingService")

local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local goalPart = game.Workspace.PathfindingTEst

local path = PFS:CreatePath()

local success, errorMessage = pcall(function()
	path:ComputeAsync(npc.PrimaryPart.Position, goalPart.Position)
end)

if success then
	for _,waypoint in pairs(path:GetWaypoints()) do
		local part = Instance.new("Part")
		part.Material = "Neon"
		part.Anchored = true
		part.CanCollide = false
		part.Shape = "Ball"
		part.Position = waypoint.Position
		part.Parent = game.Workspace
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
else
	warn(errorMessage)
end


Try increasing the AgentRadius parameter when creating path

wait(5)
local PFS = game:GetService("PathfindingService")

local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local goalPart = game.Workspace.PathfindingTEst

local path = PFS:CreatePath({
    AgentRadius = 4,--Adjust based on space
    AgentHeight = 6
})

local success, errorMessage = pcall(function()
	path:ComputeAsync(npc.PrimaryPart.Position, goalPart.Position)
end)

if success then
	for _,waypoint in pairs(path:GetWaypoints()) do
		local part = Instance.new("Part")
		part.Material = "Neon"
		part.Anchored = true
		part.CanCollide = false
		part.Shape = "Ball"
		part.Position = waypoint.Position
		part.Parent = game.Workspace
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
else
	warn(errorMessage)
end

Addingonto what @Giftdenz stated you can also try the arguement WaypointSpacing

image

This could create a straighter path but keep in mind it might take longer to compute.

so how would i use waypoint spacing

Same as this but youd put it into the table:

local path = PFS:CreatePath({
    AgentRadius = 4,--Adjust based on space
    AgentHeight = 6,
    WaypointSpacing = 2 -- change this based on the result
})

Try implementing this.