I made a script that spawns trees and then moves them if the leaves are touching other leaves. It spawns trees but I need it to repeat until the leaves are not touching
Excerpt of script
if Grnd.Material == Enum.Material.Grass and Grnd.BrickColor == BrickColor.new("Forest green") then for i = 1,10 do wait() treecopy = basetree:clone() treecopy.Parent = frm treecopy:SetPrimaryPartCFrame(Grnd.CFrame * CFrame.new(math.random(-25, 25), 0 + 5, (math.random(-25, 25)))) local results = treecopy.Leaves:GetTouchingParts() local trees = {} for i, treeCluster in pairs(results) do table.insert(trees, treeCluster) if treeCluster.Name == "Leaves" then wait() treecopy:SetPrimaryPartCFrame(treecopy.Trunk.CFrame * CFrame.new(math.random(-5, 5), 0, (math.random(-5, 5)))) treecopy.Leaves.BrickColor = BrickColor.new("Lime green") end end end end
I tried adding this after changing the color on line 14 but it doesn't work
repeat treecopy:SetPrimaryPartCFrame(treecopy.Trunk.CFrame * CFrame.new(math.random(-5, 5), 0, (math.random(-5, 5)))) wait() until treeCluster.Name ~= "Leaves"
And tried this also
until results ~= "Leaves"
This script does move it and change the color(so I can see which ones were moved) but it will still place the trees intersecting with other trees.