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
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