Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

Generating [closed]

Asked by 10 years ago

I am trying to make a Minecraft-like game on ROBLOX and I tried to make a generate script for grass. Here is what I tried:

grass = script.Parent.Grass
blocks = {grass}
grass.Anchored = true

for i,v in pairs(blocks) do
    generatedblocks ="Part", Workspace)
    generatedblocks.Name = "Grass"
    generatedblocks.Size = grass.Name
    generatedblocks.Anchored = true
    generatedblocks.Position = -- I dont know what to put here and the rest.

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
Answered by
jobro13 980 Moderation Voter
10 years ago

To make a straightforward generation you first need to think of what you need. Let's strip down the problem to the base problem: we need to generate a blocky-like landscape. You can later implement biomes and types of blocks.

Reviewing your current code: there are some problems in it.

First of all you are looping over "blocks", a table which only has one member. That means that it will run it's code only once. I wouldn't do that, I would loop over an x and z range (the positions). To chose a block you can always use math.random to get a random block from the list.

Second: you are assigning Size to a Name. Size is a Vector3 and Name is a string. This will always conflict. I take that script.Parent.Grass is a brick: why not clone it?

The simplest terrain generator will just loop over all x and z positions and will assign a random height to it. You will see that the terrain will be extremely "peaky". If you run the code you will see what I mean. It is better to study random "noise" generators - I would suggest Perlin Noise.

local block = script.Parent.Grass
local function GetBlock()
    return block:Clone()
local function GetSize()
    return block.Size.z
-- Assing random position ranges
local x_min, x_max = -100,100
local z_min, z_max = -100, 100
local y_min, y_max = 1,10 -- this is in block units.
for x = x_min, x_max, GetSize() do 
    for z = z_min, z_max, GetSize() do
        local height = math.random(y_min, y_max)
        for y = GetSize()/2, GetSize() * (height + 0.5), GetSize() do
            local block = GetBlock()
            block.CFrame =,y,z)
            block.Parent = game.Workspace
        wait() -- due the amount of recurses; wait, otherwise roblox will crash
Thanks. But is there a way to fix it? Or a way to understand it so 'I' can fix it? It doesn't connect and stuff. Try it and you will see Randomplayer121 -2 — 10y
I see that my code is indeed incorrect - but you will see that it will work if the height of the block is exactly the same as the z size of the block. You will need to create a block (grass) which has Size.x == Size.y == Size.z. In that case it will work. Otherwise you have to edit the script so GetSize will return the size on the axis itself (GetSize("x")) so you can fix this problem. I tested i jobro13 980 — 10y
So I have to make another grass block? If not, could you send me the new code and you can put comments on it. Randomplayer121 -2 — 10y
Try it with a "Grass block" with Size =,4,4) (note: FormFactor must be Custom). You will see it will work. jobro13 980 — 10y
i tried it by making it grass and with the size and the formfactor was custom. It didn't work Randomplayer121 -2 — 10y
Log in to vote
Answered by 10 years ago

Well I'm not quite sure what your asking because I know you can generate random terrain but I'm not quite sure about generating Grass Blocks even though it seems simple enough.

Well I could help you with setting the position it would have to be using the code,0,0) and you would have to find a way to keep adding that up evenly, throughout the base plate. You could also use Loop if that might give you any ideas? Not quite sure how this script would work but it is interesting.