Odd EditableMesh texturing

I have used the EditableMesh class in order to draw a plane with the given quantity of verticies.

Here is how the mesh looks like if all the verticies are on Y = 0

Here is the exact same mesh but the Y value is based on a math.noise function
image

Here is my code on making the mesh:

local function DrawGridMesh(mesh: EditableMesh, def: number, yFunction: (number, number)->(number))
	local vertexMatrix = {}
	for X = 1, def do
		vertexMatrix[X] = {}
		for Y = 1, def do
			vertexMatrix[X][Y] = mesh:AddVertex(
				Vector3.new(
					(X-1)/(def-1) - 0.5,
					yFunction(X, Y),
					(Y-1)/(def-1) - 0.5
				))
			
		end
	end
	for X = 1, def - 1 do
		for Y = 1, def - 1 do
			mesh:AddTriangle(
				vertexMatrix[X][Y],
				vertexMatrix[X][Y+1],
				vertexMatrix[X+1][Y+1]
			)
			mesh:AddTriangle(
				vertexMatrix[X+1][Y+1],
				vertexMatrix[X+1][Y],
				vertexMatrix[X][Y]
			) 
		end
	end
	return vertexMatrix
end


behaviour when Y is math.sqrt(Z+X)


behaviour when math.sqrt(X^2 + Z^2) / 10