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

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

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

7 comments

1

I knew it.

0

Lol shush. I tried to do it for about another 3-5 hours and it didn't work XDDDD

0

I continued even after I said I'm going to bed. XD

0

This isn't Minecraft though...

0

I'm trying to recreate don't starve.

1

Minecraft and Roblox r both different.

2

i forbid you to start comparing roblox and minecraft

1 answer

✓ Accepted answer

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

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