How to close frames within the frame that are open with the Close button?

The frames have different names, I would like to close the frame that was visible as in the image below, Thank you!

local TextButton = script.Parent

for i,v in pairs(TextButton:GetDescendants()) do
	if v:IsA("TextButton") then
		v.MouseButton1Down:Connect(function()	
					
		end)
	end
end

What about that:

local frame = script.Parent
local button = frame.Close

button.MouseButton1Click:Connect(function()
	frame.Visible = false
end)

Note: this will make the frame invisible but it will still exist if this is one time menu you should rather destory it.

This script closes every menu, I would like to close it (B001, G001, G002, G003, G004… Whichever one is open) as in the image above without using the frame name (local frame = script.Parent.G003 ), Thanks for answering!

local frame = script.Parent
local button = frame.Close

button.MouseButton1Click:Connect(function()
	

for i,v in pairs(frame:GetDescendants()) do
	if v:IsA("Frame") and v.Visible == true then
	v.Visible = false
end
end
end)
`Ë‹Ë‹

What do you mean by “is open”? Do you want to close all subframes (B001, G001…) when by clicking “X” button? If so you use this code:

local frame = script.Parent
local button = frame.Close

button.MouseButton1Click:Connect(function()
    for _, child in pairs(frame:GetChildren()) do
        if child:IsA('Frame') then
            child.Visible = false
        end
    end
end)

I’m not sure what do you want to achieve so there is one more code that might work as you want:

local frame = script.Parent
local button = frame.Close

button.MouseButton1Click:Connect(function()
    for _, descendant in pairs(frame:GetDescendants()) do
        if descendant:IsA('GuiButton') and descendant.Name ~= 'Close' then
            descendant.Parent.Visible = false
        end
    end
end)
1 Like

What do you mean “is open”?
I mean visible!

The second script works perfectly that’s what I was wanting!

Thanks!