Inconsistent terrain generation problem

Im making a block-based terrain generation system. It uses chunks (kinda like minecraft) to generate, but Im having a problem

For some reason, on the first row and column of the chunk generation, It seems like it is drastically different terrain.

I have tried rewriting the generation code entirely and the bug still happens, I cant think of anything wrong with it.

Here is my code, and for clarification, chunkheight is 64, chunksize is 16, xindex and yindex are set to 1, and generatedChunkData is an array of the chunk’s blocks

		for y = 1, chunkheight do
			for x = 1, chunksize do
				for z = 1, chunksize do
					local noiseheight = math.noise((x+(xindex*chunksize))/noiseScale,(z+(zindex*chunksize))/noiseScale,seed) * chunkheight/2 + chunkheight/2
					print(x)

					if noiseheight > y then
						table.insert(generatedChunkData, 2) -- set block to stone
					elseif math.ceil(noiseheight) == y then
						table.insert(generatedChunkData, 3) -- set block to grass
					else
						table.insert(generatedChunkData, 1) -- set block to air
					end
				end
			end
		end

Any help would be appreciated.

This appears to be caused by your chunks not lining up exactly. Probably due to a typo or otherwise incorrect math in your noise call. I’d suggest checking the values of blocks that are on edges of neighboring chunks to make sure that the noise pattern is being correctly spliced.