Entity using Pathfinding seems to try and walk through walls?

Hello! I’m currently trying to make a pathfinding base for entities in my game!

What I’m trying to do is make this entity go around the level repeatively, but for some reason it gets stuck on walls! I’ve tried to create smaller spacing, but it just seems to create a large gap between the two points!


For reference, this is my code

local Workspace = game:GetService("Workspace")
local PathfindingService = game:GetService("PathfindingService")

while true do task.wait()
	local path = PathfindingService:CreatePath({
		AgentRadius = 4,
		AgentHeight = 7,
		AgentCanJump = false,
		AgentCanClimb = false,
		WaypointSpacing = 2
	})
	
	local finishPosition = nil
	local RandomPosition = {}
	
	for i,v in pairs(workspace.LEVELS.Level:FindFirstChildWhichIsA("Model"):GetChildren()) do
		table.insert(RandomPosition,v.EntityPosition.Position)
	end
	
	local random1 = math.random(1,#RandomPosition)
	finishPosition = RandomPosition[random1]
	
	-- Compute the path
	local success, errorMessage = pcall(function()
		local startPosition = script.Parent.Step.Position
		path:ComputeAsync(startPosition, finishPosition)
	end)

	-- Confirm the computation was successful
	if success and path.Status == Enum.PathStatus.Success then
		-- For each waypoint, create a part to visualize the path
		for _, waypoint in path:GetWaypoints() do
			local Highlight = Instance.new("Highlight")
			local part = Instance.new("Part")
			part.Position = waypoint.Position
			Highlight.Parent = part
			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.Points
		end
		for _, waypoint in path:GetWaypoints() do -- This is what moves it to each waypoint
			script.Parent.Humanoid:MoveTo(waypoint.Position)
			script.Parent.Humanoid.MoveToFinished:Wait()
		end
		workspace.Points:ClearAllChildren()
	else
		print("Path unable to be computed, error: {errorMessage}")
	end
end

Try increasing the agentradius as well as decrease the height a bit.

This made it a bit less common, but for some reason it still happens

I also notice that the longer the Path is, the less squares are highlighted (ALL squares should be highlighted in my script. Why is this happening?)