Help with perlin noise math

local X,Y,Z = 15,15,15
local posg = {}
local Smooth = 10
for x = 1,X do
	posg[x] = {}
	for y = 1,Y do
		posg[x][y] = {}
		for z = 1,Z do
			posg[x][y][z] = {} 
			local part = Instance.new("SpawnLocation")
			part.Anchored = true
			part.Parent = workspace
			part.Position = Vector3.new(x*5, y*5, z*5)
			part.Size = Vector3.new(5, 5, 5)
			part.Transparency = 1 - math.noise(
				(X/Smooth) + x/Smooth * 3,
				(Y/Smooth) + x/Smooth * 3,
				(Z/Smooth) + x/Smooth * 3
			)
		end
	end
end

i am trying to make a perlin noise system and have only used 2d arrays up to this point and am unable to figure out how to go about doing my math

My end goal:

I’m confused about what you’re actually trying to achieve, and what does/doesn’t it currently do?

What i want is it to make a cave system out of a cube here is what i have currently
image
(clearly not desireable)
Something like what i want:
image
As i said i have only so far done 2d perlin terrain and scaled the y axis based on the perlin but i do not know how i would go about doing this in a 3d system

I might be a little late, but what was the solution?