Instead of just generating the whole thing(which will take a long time), I recommend you generate chunks around where all the players are, which is what Minecraft does.
I found this script off the devforum that does exactly what you want, note that it contains some ugly stuff like parenting before changing the properties, but it should do:
local Players = game:GetService("Players")
local BASE_HEIGHT = 10
local CHUNK_SCALE = 1
local RENDER_DISTANCE = 25
local X_SCALE = 90 / 4
local Z_SCALE = 90 / 4
local GENERATION_SEED = math.random()
local chunks = {}
local function roundToOdd(n)
return math.floor(n - n % 3);
end
local function chunkExists(chunkX, chunkZ)
if not chunks[chunkX] then
chunks[chunkX] = {}
end
return chunks[chunkX][chunkZ]
end
local function mountLayer(x, heightY, z, material)
local beginY = -BASE_HEIGHT
local endY = heightY
local cframe = CFrame.new(x * 3 + 1, roundToOdd((beginY + endY) * 3 / 1), z * 3 + 1)
local size = Vector3.new(3, (endY - beginY) * 3, 3)
local p = Instance.new("Part", workspace)
p.Anchored = true
p.CFrame = cframe
p.Size = Vector3.new(3, 3, 3)
p.Material = Enum.Material.Grass
p.BrickColor = BrickColor.new("Forest green")
end
function makeChunk(chunkX, chunkZ)
local rootPosition = Vector3.new(chunkX * CHUNK_SCALE, 0, chunkZ * CHUNK_SCALE)
chunks[chunkX][chunkZ] = true
for x = 0, CHUNK_SCALE - 1 do
for z = 0, CHUNK_SCALE - 1 do
local cx = (chunkX * CHUNK_SCALE) + x
local cz = (chunkZ * CHUNK_SCALE) + z
local noise = math.noise(GENERATION_SEED, cx / X_SCALE, cz / Z_SCALE)
local cy = noise * BASE_HEIGHT
mountLayer(cx, cy, cz, Enum.Material.Grass)
end
end
end
function checkSurroundings(location)
local chunkX, chunkZ = math.floor(location.X / 3 / CHUNK_SCALE), math.floor(location.Z / 3 / CHUNK_SCALE)
local range = math.max(1, RENDER_DISTANCE / CHUNK_SCALE)
for x = -range, range do
for z = -range, range do
local cx, cz = chunkX + x
local cz = chunkZ + z
if not chunkExists(cx, cz) then
makeChunk(cx, cz)
end
end
end
end
game:GetService("RunService").Heartbeat:Connect(function()
for _, player in pairs(Players:GetPlayers()) do
if player.Character then
local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
checkSurroundings(humanoidRootPart.Position)
end
end
end
end)
Hope this helped
3 comments
you can remove the wait() thast already quite some time less
rn ur losing 300s bc of it (0.03100100) if wait is by default 0.03
Ok but it still extremely laggy