How can I make a script in my gui that reduces amount of trees

Hello, I was wondering how I can make a script that would make trees in a folder transparent and also have collision off when you choose a button in my GUI and if you select Low or Default the collision only works for the bark

This is the folder:
image

image

im not really to good with scripting so if anyone can help that would be great!

1 Like

You could do something like this, where p is a percentage of trees that you would want to remove.

Here is an example that removes 75% of trees, by picking a random one.

local trees = workspace.Trees:GetChildren()
local p = 0.75
local n = math.floor(p * #trees)

for i = 1, n do
    trees[math.random(1, #trees)]:Destroy()
end
2 Likes

Adding on to Andrew’s response

Assuming the “Trees” folder is in workspace, and the localscript is in the frame:

local p = 0.75

local def, low, no = script.Parent.Default, script.Parent.Low, script.Parent.No;

local folder = workspace.Trees;

local n = math.floor(p * #folder:GetChildren())

def.MouseButton1Click:Connect(function()
    local treesFolder = game.ReplicatedStorage:FindFirstChild("lowTrees");
    if not treesFolder then return end;
    for i,v in pairs(treesFolder:GetChildren()) do
        v.Parent = folder;
    end
end)

low.MouseButton1Click:Connect(function()
    local treesFolder = game.ReplicatedStorage:FindFirstChild("lowTrees") or Instance.new("Folder");
    treesFolder.Name = "lowTrees";
    treesFolder.Parent = game.ReplicatedStorage;
    for i = 1, n do
        folder:GetChildren()[math.random(1, #folder:GetChildren())].Parent = treesFolder;
    end
end)

no.MouseButton1Click:Connect(function()
    local treesFolder = game.ReplicatedStorage:FindFirstChild("lowTrees") or Instance.new("Folder");
    treesFolder.Name = "lowTrees";
    treesFolder.Parent = game.ReplicatedStorage;
    for i,v in pairs(folder:GetChildren()) do
        v.Parent = treesFolder;
    end
end)
1 Like

Forgot to mention this is the gui

oops
image

local p = 0.75

local def, low, no = script.Parent.Default, script.Parent.Low, script.Parent.None;

local folder = workspace.Trees;

local n = math.floor(p * #folder:GetChildren())

def.MouseButton1Click:Connect(function()
    local treesFolder = game.ReplicatedStorage:FindFirstChild("lowTrees");
    if not treesFolder then return end;
    for i,v in pairs(treesFolder:GetChildren()) do
        v.Parent = folder;
    end
end)

low.MouseButton1Click:Connect(function()
    local treesFolder = game.ReplicatedStorage:FindFirstChild("lowTrees") or Instance.new("Folder");
    treesFolder.Name = "lowTrees";
    treesFolder.Parent = game.ReplicatedStorage;
    for i = 1, n do
        folder:GetChildren()[math.random(1, #folder:GetChildren())].Parent = treesFolder;
    end
end)

no.MouseButton1Click:Connect(function()
    local treesFolder = game.ReplicatedStorage:FindFirstChild("lowTrees") or Instance.new("Folder");
    treesFolder.Name = "lowTrees";
    treesFolder.Parent = game.ReplicatedStorage;
    for i,v in pairs(folder:GetChildren()) do
        v.Parent = treesFolder;
    end
end)
1 Like

Thanks man ill try to learn off this so i can do it myself lol

appreciate you guys taking time to help :smiley: