Faster Terrain Generation Help?

I am making a procedural terrain generator, using 3d noise for underground enviroments. The problem is that it is too slow for larger maps and use too much script activity and rate:

I would like to know if there is a faster terrain function. I saw WriteVoxels and thought that maybe it could work but I am not sure and I don’t really understand it yet.
I also would like to know if using FillBlock() once to generate a 1x10x1 terrain is as performance friendly and as fast as using FillBlock() 10 times to generate 1x1x1.
Also would like to know some tips you might have about accelerating this process.

Things I tried:

  • Worm noise instead of 3d (is a bit faster, but still lags the server while generating and isnt as fun as this one);
  • Chunk system (works, but even loading closer chunks lag).

Here is the code if it might help you solving this problem for me:

local resolution = 150
local frequency = 10
local power = 20
local Seed = math.random(1,1000000)
local MaxDensity = -2
local MaxDensityg = -3
local scale = 8
script:ClearAllChildren()
workspace.Terrain:Clear()
for x = 0, resolution do
wait()
for y = 0, resolution do
	for z = 0, resolution do
		local X = math.noise((y/frequency),(z/frequency),Seed)*power
		local Y = math.noise((x/frequency),(z/frequency),Seed)*power
		local Z = math.noise((y/frequency),(x/frequency),Seed)*power
		local Density = X + Y + Z
		if y <=2 then
			workspace.Terrain:FillBall(Vector3.new(x*scale,y*scale,z*scale),scale,Enum.Material.Basalt)
		elseif y >= resolution-2 then
			workspace.Terrain:FillBall(Vector3.new(x*scale,y*scale,z*scale),scale,Enum.Material.Grass)
		elseif Density < MaxDensityg then
			if y > 10 then
				workspace.Terrain:FillBall(Vector3.new(x*scale,y*scale,z*scale),scale,Enum.Material.Ground)
			else
				workspace.Terrain:FillBall(Vector3.new(x*scale,y*scale,z*scale),scale,Enum.Material.CrackedLava)
			end	
		elseif Density < MaxDensity then
			workspace.Terrain:FillBall(Vector3.new(x*scale,y*scale,z*scale),scale,Enum.Material.Rock)
		end
	end
end
end

Hey, friend! I would try looking into Actors for multithreading.

Max made an awesome open source file for ya’! :'D

I actually tested that generator before and even spoke with him. He adapted the code from roblox’s generation system. And I remember it not lagging when I used it. I don’t know why, but I tried it now and the performance is way worse than before (300 activity). It might be something to do with my pc though, which is also weird because its the same device I tested the script with before.

At least it helped me with the question about writevoxels being better in performance than fill. It seems both are laggy when used massively. But I think that maybe preloading the chunk data into ways to write on voxels might save up some lag when generating them afterwards. So I can make a code keep storing chunk data for terrain:WriteVoxels() in a distance way further than the player can see (which can be done with more yields, so it lags lass), and instead of iterating through noises again I just use that data to generate the chunk. But it does look like a lot of work for something that might not even work. I think it might be better for me to keep with the worm noise cave system and focus more on surface landscape and dungeons/random structures.