Okay, so, I made this script that generates a certain amount of trees in random positions, a random leaf colour, and a random size.
It works pretty well, but sometimes this will happen:
I don’t mind the leaves going inside each other, but sometimes the tree trunks go inside each other, but that doesn’t look good and isn’t realistic.
I am trying to stop the tree trunks from going inside of each other.
Here is the script(Note:I am not the best of scripting, I have only been doing it for a few months.):
For context this is how the tree is laid out:
local ServerStorage = game:GetService("ServerStorage")
local Tree = ServerStorage:WaitForChild("Tree")
local Button = workspace.Part.ClickDetector
local function treeGenerated()
local TreeProperties = {
Position = Vector3.new(math.random(0,512), math.random(5,10), math.random(0,512));
LeaveSize = Vector3.new(math.random(5,10), math.random(5,10), math.random(5,10));
LeaveColor = {BrickColor.new("Forest green"), BrickColor.new("Sea green"), BrickColor.new("Camo")}
}
local NewTree = Tree:Clone()
NewTree.Parent = workspace
NewTree.Wood.Position = TreeProperties.Position - Vector3.new(256, 0, 250)
NewTree.Leave.Position = TreeProperties.Position - Vector3.new(256, 0, 250) + Vector3.new(0,11,0)
NewTree.Leave.Size = TreeProperties.LeaveSize + Vector3.new(0,0.5,0)
local RandomLeaveColour = math.random(1, #TreeProperties.LeaveColor)
NewTree.Leave.BrickColor = TreeProperties.LeaveColor[RandomLeaveColour]
end
Button.MouseClick:Connect(function()
for i = 0, 1000, 1 do
treeGenerated()
end
end)
This is the game(if you want to see it):
Press the gray block near spawn to generate 1000 trees, you can press it multiple times if you want.