Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get all children in a GUI and make those children (frames) invisible?

I have been wondering for a while and tried something that doesn't work.

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent:GetChildren().Visible = false
end)

1 comment

1

I fixed my issue.

1 answer

✓ Accepted answer

GetChildren will return an array of Instances that descend one step below the called upon Object. If I create an arbitrary table of elements to represent Instances, you can visually see why this isn’t working:

{1,2,3}.Visible = true

To actually reach the Instance to change a property, you must reference it within the table, or use a pairs loop to traverse to it, or iterate through multiple Instances to apply the same change.

local ScreenGui = script:FindFirstAncestorOfClass("ScreenGui")
local Children = ScreenGui:GetChildren()

for _,Frame in pairs(Children) do
    if (Frame:IsA("Frame")) then
        Frame.Visible = true
    end
end

3 comments

0

It seems to not work.

1

I accidentally said True my apologies, however you should’ve caught this so please next time understand the code instead of copy-pasting.

0

Oh lmao sorry. Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.