VGUI Change Team Menu

I used this code from the Lua Tutorial Series because I am just starting to get into Lua and noticed that when I click the team to join it doesn’t close the menu. What would I add to close it aswell?


function set_team()
 
local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 2, ScrH() / 2 ) --Set the window in the middle of the players screen/game window
frame:SetSize( 200, 210 ) --Set the size
frame:SetTitle( "Change Team" ) --Set title
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:MakePopup()
 
team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( frame:GetTall() / 2, 5 ) --Place it half way on the tall and 5 units in horizontal
team_1:SetSize( 50, 100 )
team_1:SetText( "Team 1" )
team_1.DoClick = function() --Make the player join team 1
    RunConsoleCommand( "team_1" )
end
 
team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( frame:GetTall() / 2, 105 ) --Place it next to our previous one
team_2:SetSize( 50, 100 )
team_2:SetText( "Team 2" )
team_2.DoClick = function() --Make the player join team 2
    RunConsoleCommand( "team_2" )
end
 
end
concommand.Add( "team_menu", set_team )


Also, is there a good looking alternative to use instead of this menu?

Use the ‘:Close()’ function on the frame in question, in your case
[lua]frame:Close()[/lua]

Like so:

[lua]team_1.DoClick = function() --Make the player join team 1
RunConsoleCommand( “team_1” )
frame:Close()
end[/lua]

[lua]team_2.DoClick = function() --Make the player join team 2
RunConsoleCommand( “team_2” )
frame:Close()
end[/lua]

I got this message
[gamemodes\mygamemode\gamemode\cl_init.lua:21] ‘=’ expected near ‘frame’
[cpp]
There was a problem opening the gamemode file ‘MyGamemode/gamemode/cl_init.lua’

try [lua]
team_1:GetParent():Close()
team_2:GetParent():Close()
[/lua]

My apologies, I tried your old one again and I had a typo. Thanks!

I thought that would work, glad you got it working.