Hello. I am making a script that when a button is pressed, all the buttons in a certain folder are invisible. How can I get all the buttons instead of listing each and individually turning them off?
Use :GetChildren() on the folder containing the buttons.
so like this?
You need to loop through the array returned by :GetChildren() like so:
for i, v in folder:GetChildren() do
-- v is a button object you can do whatever you want with it
end
sorry I am confused. Like this?
( i do not know how to make a lua code block btw, sorrry in advanced)
No, v is a variable you can use it on its own and it will be a button object.
for _, Buttons in pairs (YourFolderName:GetChilden()) do
Buttons.Visible = false
end
But if that folder contain other things than just buttons then you have to make a statement.
No it would be like this
script.Parent.MouseButton1Click:Connect(function()
wait(.5)
local folder = script.Parent.Parent.Hair.A
for i, v in pairs(folder:GetChildren()) do
v.Visible = false
end
end)
You could define a local variable at the top and store all the buttons
local Buttons = YourFolderName:GetChildren()
Then when a specific button is activated you could loop through the table and turn all the other buttons invisible:
for _, button in pairs(Buttons) do
button.Visible = false
end
pairs is no longer needed for iteration btw
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.