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