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

Why doesn't my script successfully generate a biome and connect them together?

Asked by 9 years ago

For some reason, my script isn't really working the way I want it to. it positions my first block and then bam, the rest are sent to variations of the vectors (1,1,1). I've tried to generate it multiple times. Is there anything I can do different to make it work? ( also nothing in the output) Here is the script:

_G.GenerateBiomes = function()
    local storage = game.Workspace.Biomes
    local Marsh, Forest, Savannah = storage.Marsh, storage.Forest, storage.Savannah
    local Terrains = game.ReplicatedStorage.Terrains
    for x=1,50 do
        local part = Terrains.Grass_Terrain:Clone() -- Creates a Part and makes it a descendant of Workspace
        part.Parent = Forest
        part.Name = "Generated_Grass["..x.."]"
        part.Anchored = true -- Prevents the part from moving.
        if x ~= 1 then
            part.Position =((Vector3.new(math.random(70, 100), 1, math.random(1, 84)) - Vector3.new(Forest:FindFirstChild("Generated_Grass[".. x - 1 .."]"))).magnitude/Vector3.new(83.96, 1, 77.71))
        else
            part.Position = Vector3.new(-357.015, 1.3, -872.373)
        end 
    end
end
1
I knew it. woodengop 1134 — 9y
0
Lol shush. I tried to do it for about another 3-5 hours and it didn't work XDDDD deputychicken 226 — 9y
0
I continued even after I said I'm going to bed. XD deputychicken 226 — 9y
0
This isn't Minecraft though... FearMeIAmLag 1161 — 9y
View all comments (3 more)
0
I'm trying to recreate don't starve. deputychicken 226 — 9y
1
Minecraft and Roblox r both different. woodengop 1134 — 9y
2
i forbid you to start comparing roblox and minecraft drew1017 330 — 9y

1 answer

Log in to vote
3
Answered by
duckwit 1404 Moderation Voter
9 years ago

In addition to your x variable, you'll also need a second variable (z) as you're indexing the positions of terrain elements in a plane - a two-dimensional space.

storage = game.Workspace.Biomes
unitTerrain = game.ReplicatedStorage.Terrains.Grass_Terrain --A single part of terrain
unitTerrain.CFrame = CFrame.new(unitTerrain.Position) --Correct Rotation

width = unitTerrain.Size.X
length = unitTerrain.Size.Z

gridSize = 50 --Assuming a square grid

startPosition = Vector3.new(-357.015, 1.3, -872.373) --lower left corner of grid

for x = 1, gridSize do
    for z = 1, gridSize do
        local newPart = unitTerrain:Clone()
        newPart.Anchored = true
        newPart.Parent = workspace
        newPart.Position = startPosition + Vector3.new((x-1)*width, 0, (z-1)*length)
    end
end
Ad

Answer this question