Nice script!
In your script you requested performance tips; here's a more efficient version:
local ms = 1500 -- Map size (limit before timeout is around 3000)
local amp = 200 -- How high/low the terrain goes (this affects biomes)
local scale = 150 -- How big the biomes are (the higher the bigger)
local blockScale = 4 -- How blocky the terrain looks
local waterLevel = -1 -- self explanatory
local terrainThickness = 2 -- was 30
local waterThickness = 2 -- was 80
local seed = math.random(-10000, 10000)
print(seed)
local done = Instance.new("BoolValue")
done.Name = "TerrainDone"
done.Value = false
done.Parent = workspace
local v3 = Vector3.new
local cf = CFrame.new
local terrain = workspace.Terrain
local size = v3(blockScale, terrainThickness, blockScale)
local pauseEvery = 0.1 -- pause every this many seconds
local nextPause = tick() + pauseEvery
local stepped = game:GetService("RunService").Stepped
local begin = tick()
for x = -ms/2, ms/2 do
if tick() >= nextPause then
stepped:Wait()
nextPause = tick() + pauseEvery
end
local px = blockScale * x
for z = -ms/2, ms/2 do
local pz = blockScale * z
local height = (math.noise(x/scale, z/scale, seed) * amp) + waterLevel
if height <= waterLevel then
terrain:FillBlock(cf(v3(px, waterLevel - waterThickness/2, pz)), v3(size.X, waterThickness, size.Z), Enum.Material.Water)
else
local material = -- I encourage playing with the values after the "+"
height < waterLevel + 4 and Enum.Material.Sand
or height < waterLevel + 80 and Enum.Material.Grass
or Enum.Material.Snow
terrain:FillBlock(cf(v3(px, height, pz)), size, material)
end
end
end
print("Done in", math.floor((tick() - begin)*100)/100,"sec")
done.Value = true
Efficiency improvements:
- Localized some of the variables/functions (this could be done even more, though I'm not sure if the impact is noticeable)
- Used 'and or' instead of 'if'
- Skipped using a part
- Kept track of time passed (with 'tick') instead of 'wait' (if you move the relevant code into the 'z' for loop you can make the terrain generate even larger)
- (The biggest speed improvement) Make the terrain only 2 thick (though sometimes holes can generate depending on what settings you use)