Pathfinding not avoiding obstacles

Hello! I am trying to figure out why my AI doesn’t avoid obstacles even though it moves towards the player. I am not that experienced with pathfinding so it very well could be a simple issue but I thought I’d give it a shot here. Here is a snippet of the code:

--------------------------------------------------------
local function locateTarget()
	local playerList = game.Players:GetPlayers()
	local distance = nil
	local direction = nil
	local nearestPlayer = nil

	for _, player in pairs(playerList) do
		local character = player.Character
		if character then
			local dvector = (player.Character.HumanoidRootPart.Position - ghost.HumanoidRootPart.Position)
			if not nearestPlayer then
				nearestPlayer = player 
				distance = dvector.Magnitude
				direction = dvector.Unit
			elseif dvector.Magnitude < distance then
				nearestPlayer = player
				distance = dvector.Magnitude
				direction = dvector.Unit
			end
		end
	end

	return nearestPlayer, distance, direction
end
--------------------------------------------------------
local pathfinding = game:GetService("PathfindingService")

while true and ghost.GhostHumanoid.Health >= 1 do
	local nearestPlayer, distance, direction = locateTarget()
	if nearestPlayer then
		local path = pathfinding:CreatePath({
			AgentRadius = 2,
			AgentHeight = 5,
			AgentCanJump = false,
			AgentCanClimb = false
		})
		path:ComputeAsync(ghost.HumanoidRootPart.Position, nearestPlayer.Character.HumanoidRootPart.Position)
		local waypoints = path:GetWaypoints()
		if distance <= targetingDistance and distance >= stoppingDistance then
			for _, waypoint in pairs(waypoints) do
				ghost.GhostHumanoid:MoveTo(waypoint.Position)
			end
		else
			ghost.GhostHumanoid:Move(Vector3.new())
		end

		--local pickedAttack = math.random(1, #useableAttacks)
		--useableAttacks[pickedAttack](distance, nearestPlayer)
	end
	wait(0.1)
end

--------------------------------------------------------

Any help will be greatly appreciated!