How could I optimize my world generation script?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I need to optimize my world generation.
  2. What is the issue? Include screenshots / videos if possible!
    Even my gaming laptop can barely handle it when it’s fully generated (I keep my laptop plugged in)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried making unions with each part of land I generate, but it just causes a lot of errors.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local partContainer = game.Workspace:WaitForChild("World")
local fogScreenSize = 5
local resolution = 100
local frequency = 3
local amplitude = 10
local seed = os.time()

local function getHeight(x,z)
	local noiseHeight = math.noise(x / resolution * frequency, z / resolution * frequency, seed)
	return noiseHeight
end

local function makeChunk(chunkx,chunkz)
	for x = 0, fogScreenSize-1 do
		for z = 0, fogScreenSize-1 do
			local part = Instance.new("Part")
			part.Parent = partContainer
			part.Anchored = true
			part.Size = Vector3.new(1,1,1)
			part.BrickColor = BrickColor.new("Parsley green")

			local height = getHeight((x)+(chunkx*fogScreenSize), (z)+(chunkz*fogScreenSize))

			part.Position = Vector3.new((x)+(chunkx*fogScreenSize), (height*amplitude)+67, (z)+(chunkz*fogScreenSize))
			part.Material = Enum.Material.SmoothPlastic
		end
	end
end

for x = 0, 100 do
	for y = 0, 100 do
		spawn(function()
			makeChunk(x, y)
		end)
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You probably will have to generate terrain on demand as players encounter it. You can make it go very slightly faster by moving the common parts of the Part setup outside the loop and then cloning it inside the loop for each block.

So it should be sort of like Minecraft?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.