Pathway generator only working in one direction

I’m currently trying to make an open-sourced, configurable pathway generator. The concept of it is to easily make randomized, unnatural pathways easily. The script is fairly simple, but as of right now it only works in the Z direction. I want to make it so that it will work in any direction, but I’m not really sure how.

Script:

--SETTINGS
material = Enum.Material.Cobblestone --CHANGE COBBLESTONE TO MATERIAL OF CHOICE
color = Color3.new(0.741176, 0.670588, 0.494118) --USE COLOR3 COLOR WHEEL TO FIND A COLOR YOU LIKE
smallestSize = 2 --CHANGE THIS TO THE SMALLEST POSSIBLE SIZE YOU WANT THE PART TO BE
biggestSize = 3--CHANGE THIS TO THE BIGGEST POSSIBLE SIZE YOU WANT THE PART TO BE
randomOrientation = false --SET THIS TO TRUE IF YOU WANT RANDOM ROTATION ON EACH PART

--VARIABLES
local A = script.Parent.A
local B = script.Parent.B

local length = (A.Position - B.Position).Magnitude

--SCRIPT
for i = 1, length do
	local part = Instance.new("Part")
	part.Material = material
	part.Color = color
	part.Anchored = true
	part.Size = Vector3.new(math.random(smallestSize, biggestSize), 0.1, math.random(smallestSize, biggestSize))
	part.Parent = script.Parent
	part.CFrame = CFrame.new(B.CFrame.X + math.random(-B.CFrame.X/2, B.CFrame.X/2), (B.CFrame.Y + A.CFrame.Y)/2 - 0.5, B.CFrame.Z + i)
	if randomOrientation == true then
		part.Orientation = Vector3.new(0,math.random(-15, 15),0)
	end
end