Im making a voxel based world gen system for my game but it loads painfully slow. it took about 3 minutes to load the terrain in the image. Can anyone help with making it quicker / more effective?
local seed = math.random(1, 1000)
local MAPSIZE = 200
local MAPSCALE = MAPSIZE / 2
local GROUND_DEPTH = 5
local STONE_DEPTH = 30
local grassTemplate = script.Parent.grass
local dirtTemplate = script.Parent.dirt
local stoneTemplate = script.Parent.rock
local terrainFolder = Instance.new("Folder")
terrainFolder.Name = "GeneratedTerrain"
terrainFolder.Parent = workspace
local BLOCK_SIZE = 3
local NOISE_SCALE = 1/10
local HEIGHT_MULT = 2.5
local HEIGHT_STEP = 3
for x = -MAPSCALE, MAPSCALE do
for z = -MAPSCALE, MAPSCALE do
local height = math.floor(
math.noise(seed, x * NOISE_SCALE, z * NOISE_SCALE) * HEIGHT_MULT
) * HEIGHT_STEP
local worldX = x * BLOCK_SIZE
local worldZ = z * BLOCK_SIZE
local grassBlock = grassTemplate:Clone()
grassBlock.CFrame = CFrame.new(worldX, height, worldZ)
grassBlock.Parent = terrainFolder
for d = 1, GROUND_DEPTH do
local dirtBlock = dirtTemplate:Clone()
dirtBlock.CFrame = CFrame.new(worldX, height - d * BLOCK_SIZE, worldZ)
dirtBlock.Parent = terrainFolder
end
for d = 5, STONE_DEPTH do
local stoneBlock = stoneTemplate:Clone()
stoneBlock.CFrame = CFrame.new(worldX, height - d * BLOCK_SIZE, worldZ)
stoneBlock.Parent = terrainFolder
end
end
end
** You are now Level 1! **
you aint even beginner yet