How do i make all children invisible thats a texbutton

Hi,

how do i make everything that has the class of textbutton invisible thats a child of the parent?

Do you mean,
say you have a frame containing textbuttons and more stuff. And you want to only make those textbuttons invisible?

for _,object in pairs(script.Parent:GetChildren()) do
	if object:IsA("TextButton") then object.Visible = false else continue end
end
1 Like

Question: Could you explain to me how it works?

Should probably use GetDescendants() instead of GetChildren() if you want to get ALL textbuttons under the object in question, unless you only want the direct children and not the children’s children.

Basically that loop gets a table of objects of the children, checks if its a textbutton object, and if so, sets the visible property to false, as you have explained that you wanted it to do.

1 Like

‘for _,object’ is a loop which basically loops through all values in the provided table, in this case ‘script.Parent:GetChildren()’, and it checks if it is a textbutton. If it is, it makes it invisible. If not, it continues.

Problem with that is that it will loop through a lot of unnecessary objects.

1 Like

If you want to include ‘ImageButton’ objects you can specify the abstract ‘GuiButton’ base class instead, the ‘TextButton’ and ‘ImageButton’ classes are derived from this class.
if Child:IsA("GuiButton") then
https://developer.roblox.com/en-us/api-reference/class/GuiButton

1 Like