Closing vgui in a separate function?

hi, im trying to close a vgui made in a function in a separate function and i cant figure it out.

this is just a quick example:
function myvgui()

local menu = vgui.Create("DFrame")--i meant local, my bad
menu:SetSize(100, 100)
menu:SetTitle( "words here" )
menu:SetVisible( true )
menu:SetDraggable( false )
menu:ShowCloseButton( false )


function closevgui(menu) ----do i need this here???



concommand.Add( “close”, closevgui )

but when i do this i get this error,
“:18: attempt to call method ‘ShowVisible’ (a nil value)”
so how do i get menu in there???

also while im at it let me ask another question, i want to run the console command “stopsounds” immediatley before i use surface.PlaySound, but when i do this the concommand carries over and stops the sound from starting. how can i do this and have it still play, should i have it wait for half a second before i run it or is there something else?

any help would be appreciated, thanks in advance :smiley:

SetVisible, not ShowVisible

#2 , use a timer

[lua]timer.Simple(delay , function() – rest of script[/lua]


Also, your console command will be sending the player that used the concommand as “menu”. I suggest removing all arguments from the console command function assuming the menu is global.

ah, i messed up i meant to have it as local
would i have to use a global vgui for this or is there a way i can do what i want and have the vgui be local??