Im creating a block chunk based terrain generation system using perlin noise.
What happens is a function generates a dictionary containing the x and y position of the chunk, and the x, y, and z position of each block in the chunk.
Another function takes this dictionary and creates parts in the world in the form of the chunk data.
Problem is, whenever I run the function that converts the dictionary to physical blocks, roblox studio hangs until I tell it to force quit.
function loadChunk(chunkLoadData,chunksize,chunkheight)
local chunkxPos = chunkLoadData["xpos"]
local chunkzPos = chunkLoadData["zpos"]
local blockData = chunkLoadData["storedchunkdata"]
-- load blocks in chunk --
local counter = 0
for y = 0, chunkheight-1 do
for x = 0, chunksize-1 do
for z = 0, chunksize-1 do
local blockType = blockData[counter]
if blockType == 1 then
else
local blockPart = Instance.new("Part")
blockPart.Parent = game.Workspace.chunks
blockPart.CFrame = CFrame.new(Vector3.new(x+chunkxPos*16,y,z+chunkzPos)) -- this sets the position of the block to the block position relative to the chunk position
end
counter += 1
end
end
end
wait(0)
end
Note: chunkLoadData is the dictionary I explained before, chunksize is the width and length of the chunk, this is set to 16. The chunkheight is the height of the chunk, this is set to 64
I think the problem is that the script is trying to generate 16,384 blocks at the same time, But Im not sure how to fix this.
Any help would be appreciated