Hide last panel ?

I have 2 buttons, and when I click on it then they merge. How can I hide the last panel?


local menubut1 = vgui.Create("DButton" , gmenu)
		menubut1:SetFont("BigText")
		menubut1:SetText("Setting 1")
		menubut1:SetPos(10,28)
		menubut1:SetSize(180,35)
		menubut1.DoClick = function()
			menu1()
		end

local menubut2 = vgui.Create("DButton" , gmenu)
		menubut2:SetFont("BigText")
		menubut2:SetText("Setting 2")
		menubut2:SetPos(10,69)
		menubut2:SetSize(180,35)
		menubut2.DoClick = function()
			 menu2()
		end

local function menu1()

		 local setting1 = vgui.Create( "DPanel" , panel)
			setting1:SetPos( 200,22 )
			setting1:SetSize( 497, 375 )
			setting1:SetBackgroundColor( Color(0,0,0,0))
end

local function menu2()

		 local setting2 = vgui.Create( "DPanel" , panel)
			setting2:SetPos( 200,22 )
			setting2:SetSize( 497, 375 )
			setting2:SetBackgroundColor( Color(0,0,0,100))


end

Hide the panel with a click function for the button you want to use.


local menubut1 = vgui.Create("DButton" , gmenu)
		menubut1:SetFont("BigText")
		menubut1:SetText("Setting 1")
		menubut1:SetPos(10,28)
		menubut1:SetSize(180,35)
		menubut1.DoClick = function()
			menu1()
                        gmenu:Hide() -- You would do this to hide the frame that the buttons are on
		end


But I need to hide

local function menu1() and local function menu2()

If i click to menubut1 and then menubut2 they merge

I want to menu1 () close and open menu2 ()

If you can paste the rest of your code for a bit more context it’d be easier to give you a solution. You’d probably want to make all these panels parented to the same thing. If you can include the code that has ‘panel’, which is what setting1 & setting2 are parented to, i’ll give you a good answer.

You can’t get access to the panels you want to delete/create. You need to put them on either one of the buttons as a variable, so it can access the panel in the doclick function, or you need a global variable.

Setting 1 = Red button, Setting 2 = Green button
I want to make them disappear. I want to make them disappear, if active setting 1(red) then hide green button

I want to do so
if i press setting 1 , hide green button and show red button

or press setting 2 , hide red button and show green button

well, to be honest I still can’t really help(help as in paste you a working solution) without you showing me more of the code.

But, if all 3 of these buttons are created at the same time, instead of making them local variables create them on their parent.

[lua]parentPanel.NewPanel = vgui.Create(“whatever”, parentPanel);[/lua]

or store the green button on the red button so you can access it in the DoClick function, like this:

[lua]
local menubut1 = vgui.Create(“DButton” , gmenu)
menubut1:SetFont(“BigText”)
menubut1:SetText(“Setting 1”)
menubut1:SetPos(10,28)
menubut1:SetSize(180,35)
menubut1.DoClick = function(self)
if ( self.setting1 ) then
self.setting1:Remove(); – you can access the setting1 panel through self.setting1 variable because setting1 is stored on the menubut1 panel, which is what self is.
end;
end

menubut1.setting1 = vgui.Create( “DPanel” , panel);
menubut1.setting1:SetPos( 200,22 );
menubut1.setting1:SetSize( 497, 375 );
menubut1.setting1:SetBackgroundColor( Color(0,0,0,0) );
[/lua]

generally, there is a bunch of diff ways, but to give you the best i need to see more of your code cause with the snippet you gave i can’t really do much