Show Menu Help

So basically I’m trying to make a menu where if I press ‘I’ for example, it would stay open to allow me to actually edit a text box which is parent to the menu itself, however I can’t do that somehow, I’ve tried several times. At the moment I’m using this code:

hook.Add( "Think", "test", function()
if( !Frame13 ) then
Frame13 = vgui.Create( "ash_received_ticket_panel" )
if ( input.IsKeyDown( KEY_I ) ) then
Frame13:SetVisible( true )
Frame12:SetVisible( true )
Frame13:SetVisible( false )
Frame12:SetVisible( false )

However when I press in the Text box I is just spammed, can someone help please so when I click I the menu stays open?


Well, think runs constantly so if you’re holding down it’ll keep opening

Assign a boolean to a variable, example open = false, then check to deicde when to open it and set to true once it’s been pressed - think of it like a toggleable lightswitch

Hmmm, I don’t really understand how to actually make it toggle much… sorry I’m quite new to Lua.

Something along these lines:

local open = false

if not open then
	//code to create or make menu here
	open = true
	//code to close menu here
	open = false

Simplest Lua toggle, heres the Think opener me and my friend used for the business menu:

local toggle = false
hook.Add("Think", "HookIdentification", function()
	if input.IsKeyDown(KEY_F7) and toggle == false then
		toggle = true
			if !IsValid(Key_F) then
	elseif toggle and not input.IsKeyDown(KEY_F7) then
		toggle = false

I’d like to note thats this the old code, since I developed it once with an friend, he even said I would get full access to the code on scriptfodder, but I didn’t.