Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Stone not generating on Y Axis?

I'm attempting to create a grid that generates itself. Could someone point out to me why my stone is not only spawning in the wrong area, but not creating new layers on my Y axis?

The goal is to have bedrock spawn first, layout a 'sheet' for the base of the world and then have the rest of the terrain generate on top. The stone IS spawning, but its spawning inside of the bedrock layer and does not attempt to scale up on the Y axis.

Server Script

local Blocks = require(game:GetService("ServerScriptService"):WaitForChild("Modules"):WaitForChild("BlockStatistics"))
local worldwidth = 50 -- map size from border to border in blocks
local worldheight = 8 --[[map height from bedrock]] -127 +127 --This is the depth below sea level. Leave untouched for the vanilla experience.

function PrepareGrid()
	local COrigin = Vector3.new(-(worldwidth/2),-worldheight, -(worldwidth/2))
	
	for GridLayer = 0,worldheight,1 do
		
		-- [Bedrock Generation]
		if GridLayer <= 0 then
			for GenXBedrock = 1,worldwidth,1 do
				wait()
				local Bedrock = Blocks.Bedrock():Clone()
				Bedrock.Position = COrigin --laying bottom layer for Bedrock
				Bedrock.Position = Bedrock.Position + Vector3.new((GenXBedrock*Bedrock.Size.X),0,0)
				Bedrock.Parent = workspace
				for GenZBedrock = 1,worldwidth,1 do
					local BedrockZ = Bedrock:Clone()
					BedrockZ.Position = Bedrock.Position + Vector3.new(0,0,(GenZBedrock*BedrockZ.Size.Z))
					BedrockZ.Parent = workspace
				end
			end
		end
		
		
		-- [Stone Generation]
		if GridLayer <= (worldheight-3) then
			for GenYStone = 1,worldwidth,1 do
				wait()
				local Stone = Blocks.Stone():Clone()
				Stone.Position = COrigin  -- + Vector3.new(0,(GenYStone*Stone.Size.Y),0) -- Getting some weirdness here.
				Stone.Parent = workspace
				for GenZStone = 1,worldwidth,1 do
					wait()
					local StoneZ = Stone:Clone()
					StoneZ.Position = Stone.Position + Vector3.new(0,0,(GenZStone*StoneZ.Size.Z))
					StoneZ.Parent = workspace
					for GenXStone = 1,worldwidth,1 do
						local StoneX = Stone:Clone()
						StoneX.Position = Stone.Position + Vector3.new((GenXStone*StoneX.Size.X),0,0)
						StoneX.Parent = workspace
					end
				end
			end
		end
	end
end
PrepareGrid()

Modular Script

local Blocks = {}

local BlockSize = Vector3.new(3,3,3) --Size of blocks in-game.
local BlockShape = "Block"

Blocks.Stone = function()
	local ItemID = 1
	local BlockType = game:GetService("ServerStorage"):WaitForChild("Blocks"):WaitForChild("Terrain"):WaitForChild("Stone")
	return BlockType
end

Blocks.Bedrock = function()
	local ItemID = 7
	local BlockType = game:GetService("ServerStorage"):WaitForChild("Blocks"):WaitForChild("Terrain"):WaitForChild("Bedrock")
	return BlockType
end

return Blocks

1 answer

✓ Accepted answer

Nevermind! I managed to fix it after a few painful hours of confusing maths. Heres the working script.

local Blocks = require(game:GetService("ServerScriptService"):WaitForChild("Modules"):WaitForChild("BlockStatistics"))
local worldwidth = 16 -- map size from border to border in blocks
local worldheight = 8 --[[map height from bedrock]] -127 +127 --This is the depth below sea level. Leave untouched for the vanilla experience.
local TopLayer = 2 -- Layer to stop generating Stone and begin generating Dirt.

function PrepareGrid()
	local COrigin = Vector3.new(-(worldwidth/2),-worldheight, -(worldwidth/2))
	for GridLayer = 0,worldheight,1 do
		-- [Bedrock Generation]
		if GridLayer <= 0 then
			for GenXBedrock = 0,worldwidth,1 do
				wait()
				local Bedrock = Blocks.Bedrock():Clone()
				Bedrock.Position = COrigin --laying bottom layer for Bedrock
				Bedrock.Position = Bedrock.Position + Vector3.new((GenXBedrock*Bedrock.Size.X),0,0)
				Bedrock.Parent = workspace
				for GenZBedrock = 0,worldwidth,1 do
					local BedrockZ = Bedrock:Clone()
					BedrockZ.Position = Bedrock.Position + Vector3.new(0,0,(GenZBedrock*BedrockZ.Size.Z))
					BedrockZ.Parent = workspace
				end
			end
			-- [Stone Generation]
		elseif GridLayer <= TopLayer and GridLayer > 0 then
			for GenYStone = GridLayer,TopLayer,1 do
				wait()
				local Stone = Blocks.Stone():Clone()
				Stone.Position = COrigin + Vector3.new(0,(GenYStone*Stone.Size.Y),0)
				Stone.Parent = workspace
				for GenZStone = 0,worldwidth,1 do
					wait()
					local StoneZ = Stone:Clone()
					StoneZ.Position = StoneZ.Position + Vector3.new(0,0,(GenZStone*StoneZ.Size.Z))
					StoneZ.Parent = workspace
					for GenXStone = 0,worldwidth,1 do
						local StoneX = StoneZ:Clone()
						StoneX.Position = StoneX.Position + Vector3.new((GenXStone*StoneX.Size.X),0,0)
						StoneX.Parent = workspace
					end
				end
			end
			--[Dirt Generation]
		elseif GridLayer < worldheight then
			for GenYDirt = GridLayer,worldheight,1 do
				wait()
				local Dirt = Blocks.Dirt():Clone()
				Dirt.Position = COrigin + Vector3.new(0,(GenYDirt*Dirt.Size.Y),0)
				Dirt.Parent = workspace
				for GenZDirt = 0,worldwidth,1 do
					wait()
					local DirtZ = Dirt:Clone()
					DirtZ.Position = DirtZ.Position + Vector3.new(0,0,(GenZDirt*DirtZ.Size.Z))
					DirtZ.Parent = workspace
					for GenXDirt = 0,worldwidth,1 do
						local DirtX = DirtZ:Clone()
						DirtX.Position = DirtX.Position + Vector3.new((GenXDirt*DirtX.Size.X),0,0)
						DirtX.Parent = workspace
					end
				end
			end
		end
	end
end
PrepareGrid()

This discussion is preserved as it was. New answers, comments, and votes are closed.