Npc pathway is not avoiding trees

code:

local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local PhysicsService = game:GetService("PhysicsService")
local CollectionService = game:GetService("CollectionService")

PhysicsService:RegisterCollisionGroup("MonsterCollisions")

PhysicsService:CollisionGroupSetCollidable("MonsterCollisions","MonsterCollisions",false)

local Npc = script.Parent

local Humanoid = Npc:FindFirstChild("Humanoid")
local HumanoidRootPart = Npc:FindFirstChild("HumanoidRootPart")

local LastTick = tick()

local function WalkToPath(path)
	if path then
		local success, errorMessage = pcall(function()
			if path.Status == Enum.PathStatus.Success then
				local waypoints = path:GetWaypoints()
				for _,WayPoint in pairs(waypoints) do
					
					if WayPoint.Action == Enum.PathWaypointAction.Jump then
						Humanoid.Jump = true
						local part = Instance.new("Part")
						part.Position = WayPoint.Position
						part.Size = Vector3.new(0.5, 0.5, 0.5)
						part.Color = Color3.new(1, 0, 0.0156863)
						part.Material = Enum.Material.Neon
						part.Anchored = true
						part.CanCollide = false
						part.Parent = workspace.Waypoints
						print("jump")
						task.spawn(function()
							Humanoid.MoveToFinished:Connect(function(Reached)
								if Reached then
									part:Destroy()
								end
							end)
						end)
					else
						local part = Instance.new("Part")
						part.Position = WayPoint.Position
						part.Size = Vector3.new(0.5, 0.5, 0.5)
						part.Color = Color3.new(1, 0, 1)
						part.Anchored = true
						part.CanCollide = false
						part.Parent = workspace.Waypoints
						task.spawn(function()
							Humanoid.MoveToFinished:Connect(function(Reached)
								if Reached then
									part:Destroy()
								end
							end)
						end)
					end
					
					Humanoid:MoveTo(waypoints[#waypoints].Position)

				end
			end
		end)

		if not success then
			warn("Error computing path:", errorMessage)
		end
	end
end


local function WalkRandomly()
	local Path = PathfindingService:CreatePath({
		["AgentRadius"] = math.ceil(1.5),
		["AgentHeight"] = 100,
		["AgentCanJump"] = true,  -- Enable jumping
		["AgentCanClimb"] = true,
	})
	
	Path:ComputeAsync(HumanoidRootPart.Position,HumanoidRootPart.Position + Vector3.new(
		math.random(-50,50),
		math.random(-50,50),
		math.random(-50,50)
		))
	
	WalkToPath(Path)
end

local function Loop()
	while task.wait() do
		print(tick()-LastTick)
		if (tick()-LastTick) >= 3 then
			LastTick = tick()
			print("sa")
			
			WalkRandomly()
		end
	end
end


Loop()

video:

External Media