Alright, I just took a deep dive into Perlin noise and how it is influencing your terrain generation. Things got mathy REAL quick 
Your density range may be your problem here. Your density function is as follows:
xnoise = math.noise (x/23, z/23, seed) * 15
znoise = math.noise (z/noisescale, x/noisescale, seed) * amplitude
local density = xnoise - znoise + y`
Lower noisescale values create a more varied change from block to block (local), while a higher frequency create greater sustained changes in elevation on a more larger and grand scale on your map (global).
Then, this is the range you accept:
if density < 5 and density > 2 then
First things first, I do not see the point of setting a lower bound to Density. I personally believe this is the main culprit as to why you are having these lower level caves. Change the line to:
if density < 10 then
Next, I would reccommend changing your amplitude and noisescale values. If you want some real dynamic changes, what I implemented is variation of the amplitude and frequency per map spawn, where the minimum and maximum follow a normal distribution. Here is the code for this:
function module:LoadMap(DelayTime:number,CustomSeed,SpawnCharacter:boolean,RandomGeneration,Coins)
local function boxMuller()
-- box-muller method for normal distribution
local u1 = math.random()
local u2 = math.random()
local r = math.sqrt(-2.0 * math.log(u1))
local theta = 2.0 * math.pi * u2
return r * math.cos(theta)
end
local function scaleToDesiredRangeNorm(x, desiredMin, desiredMax)
local normalized = (x + 3.09) / (7.18)
return normalized * (desiredMax - desiredMin) + desiredMin
end
function NormalDistribution(desiredMin, desiredMax)
local x = boxMuller()
if x >= -3.09 and x <= 3.09 then
local normvar = scaleToDesiredRangeNorm(x, desiredMin, desiredMax)
return normvar
else if x < -3.09 then
local normvar = desiredMin
return normvar
else
local normvar = desiredMax
return normvar
end
end
end
local GeneralSize = 50
local mapxsize = 25
local mapysize = 26
local mapzsize = 25
local seed
local ExtraPosition = Vector3.new(0,15,0)
if CustomSeed == nil then
local Randomer = Random.new()
seed = Randomer:NextInteger(1,100000)
else
seed = CustomSeed
end
workspace.GenerationData.Seed.Value = seed
print(tostring(seed))
local minAmplitude = 6
local maxAmplitude = 17
local minNoiseScale = 8
local maxNoiseScale = 26
local noisescale = NormalDistribution(minNoiseScale, maxNoiseScale)
local amplitude = NormalDistribution(minAmplitude, maxAmplitude)
local blocksize = 5
local xnoise = 0
local ynoise = 0
local znoise = 0
local AllParts = 0
local AllPartsFolder = workspace.AllParts
-- rest of code
Let me know if this fixes your problems!