Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I make all of a frames children invisible easily [GUIs]?

Asked by 9 years ago

Here's what I've tried:

local children = script.Parent.Parent.Parent.ItemDetails:GetChildren()
children.Visible = false

Thank you in advance for any help you may provide.

2 answers

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

An easy way is to set up a table of all the children, then iterate over each one, and turn it transparent, in a short clean code.

Here's an example:

local Children=Frame:GetChildren()
for i,v in pairs(Children) --Sets up loop
    if v:IsA("GuiObject") then --Checks if it's a TextButton, TextLabel etc.
        v.Visible=false --Sets all gui's invisible
    end
end

So anyways, that's how it's done.

Now, let's try applying this to your script:

local children = script.Parent.Parent.Parent.ItemDetails:GetChildren()
for i,Child in pairs(children) do
    if Child:IsA("GuiObject") then
        Child.Visible=false
    end
end

Now your script should work correctly.


Anyways, if you have any further problems/questions, please leave a comment below. Hope I helped :P

-Dyler3

0
gosh darnit, you got it 2 minutes before me! :( unmiss 337 — 9y
0
you forgot the ''do'' after the pairs(Children) drew1017 330 — 9y
Ad
Log in to vote
1
Answered by
unmiss 337 Moderation Voter
9 years ago

This can be easily accomplished with a for loop. You were close-yet you cannot directly change the table of children it provides to false. Instead, do this:

local children = script.Parent.Parent.Parent.ItemDetails:GetChildren()
for _,v in pairs(children) do
    if v:IsA("Frame") then -- don't affect anything that isn't a frame, say, a script.
        v.Visible = false
    end
end

You could also easily put this inside a function, for example, a textbutton function. This will error unless the textbutton exists >.<

local children = script.Parent.Parent.Parent.ItemDetails:GetChildren()
script.Parent.MouseButton1Click:connect(function()
    for _,v in pairs(children) do
        if v:IsA("Frame") then -- don't affect anything that isn't a frame, say, a script.
            v.Visible = false
        end
    end
end)

Hope I helped!

0
Lol, sorry about that. You had a good answer as well though, I'll upvote :P dyler3 1510 — 9y

Answer this question