script.Parent.MouseButton1Down:Connect(function()
for i, v in pairs(game.Workspace.Vegetation.Model:GetDescendants()) do if not v:IsA("BasePart") then continue end
v.Transparency = 1
end
end)
If thatās the case. Youād need to use the Transparency
value for that, and not :Destroy()
.
Use these code snippets:
local enabled = 1
script.Parent.MouseButton1Down:Connect(function()
for i, v in pairs(game.Workspace.Vegetation.Model:GetDescendants()) do if not v:IsA("BasePart") then continue end
v.Transparency = enabled
end
enabled = math.abs(enabled - 1)
end)
Just some advice, instead of using an enabled value that is true or false, it can be helpful to set it as the value you want it to be when it is true/false. That way you have no annoying if statements.
Try this
local clicked = false
script.Parent.MouseButton1Down:Connect(function()
if clicked then
clicked = false
for i, v in pairs(game.Workspace.Vegetation:GetChildren()) do
v.Parent = game.ReplicatedStorage
end
else
clicked = true
for i, v in pairs(game.Workspace.Vegetation:GetChildren()) do
v.Parent = game.Workspace
end
end
end)
It Did Nothing Sorry and whats the ReplicatedStorage For?
local clicked = false
script.Parent.MouseButton1Down:Connect(function()
if clicked then
task.wait(1)
clicked = false
for i, v in pairs(game.Workspace.Vegetation:GetChildren()) do
v.Parent = game.ReplicatedStorage
end
else
task.wait(1)
clicked = true
for i, v in pairs(game.Workspace.Vegetation:GetChildren()) do
v.Parent = game.Workspace
end
end
end)
So we parent the trees to replicatedstorage to hide the trees from workspace. Can you recopy the script? I just fixed the mistakes.
What If I Put That into the ServerStorage? Will that affect It?
You canāt access ServerStorage from a LocalScript, so that script would likely error.
What you want is quite complicated honestly if you want to make every part transparent
Try this I guess
function transparency(parent)
for i, part in pairs(parent:GetChildren()) do
if part.ClassName == "Part" then
part.Transparency = 1
end
if #part:GetChildren > 0 then
transparency(part)
end
end
script.Parent.MouseButton1Down:Connect(function()
transparency(game.Workspace.Vegetation)
end)
What Iām pretty sure this should do is when you call the function, if goes through all the children of the thing you have as āparentā and checks if itās a part
If it is, it makes it transparent
Then it checks if that part has any children
If so, it calls the function again for part and repeats itself
I think this is called a recursive function
Then of course when you click the button, you kickstart it by setting the āVegetationā as the parent and looping through its children
Also if you want this to reverse and make stuff visible, just make it so you make the function again but change part.Transparency = 1 to part.Transparency = 0
Thereās an easier way to do that instead of making a whole new function (just add a parameter) but whatever
It Never Worked, But Iāll see what the other oneās are like.
Did you try my script? Any errors in the output? Btw local scripts never work on the server which includes services like serverscriptservice. I donāt think scripts can ever run in serverstorage because itās for storing things.
Try:
local tree = workspace.Vegetation.Model
local initialParent = tree.Parent
local intendedParent = game:GetService("ReplicatedStorage")
local hidden = false
script.Parent.MouseButton1Down:Connect(function()
if hidden then
tree.Parent = initialParent
else
tree.Parent = intendedParent
end
hidden = not hidden
end)
As long as Iām understanding that the item youāre trying to hide is workspace.Vegetation.Model
, this should work. Tested myself just now. @CriticalGorilla had a good idea with parenting to ReplicatedStorage since making a model transparent is a situational task.
let me See the output, and I will get back to you.
Oh if it didnāt work then⦠try this?
local vegetationClone = game.Workspace.Vegetation:Clone()
script.Parent.MouseButton1Down:Connect(function()
game.Workspace.Vegetation:Destroy()
end)
Then, when you want the vegetation back, just add
local vegetationClone = game.Workspace.Vegetation:Clone()
script.Parent.MouseButton1Down:Connect(function()
game.Workspace.Vegetation:Destroy()
--some sort of if statement to check if the vegetation is currently
--present, and if it isnt then run the following code:
local newVegetation = vegetationClone:Clone()
newVegetation.Parent = game.Workspace
end)
Simpler and should leave less room for error, although likely still quite demanding to undo the whole thing at least
I am Not Finding any errors, But Should I Can to a Normal Script and Not a Localscript?
Will that make it Better?
If you want everyone (every single player) to no longer see the model you are trying to hide, then yes, but that would require multiple scripts (including a LocalScript) and is likely not what you want.
oh⦠Then I just Wasted everyoneās time Then Sorry I thought you could do it just With One Script.
I recommend reading up on RemoteEvents (again, if you want everyone elseās trees to disappear when any player clicks this button).