Close Derma after F1 presssed again

So I have recently decided it was time I started to learn how to code more than just the plain basic, so I am making an F1 menu for DarkRP, however I am wanting it to close after I press F1 again. I have tried multiple methods with help from a friend but still no luck, maybe one of you guys could help me? I made it open after pressing F1 it just wont close, so here is the code:

local localply = LocalPlayer()

local function ShadowF1Frame()

if localply.F1Frame and localply.F1Frame:IsValid() then
 
	localply.F1Frame:Close()

else
	local F1Frame = vgui.Create( "DFrame" )
	F1Frame:SetPos( 5, 5 )
	F1Frame:SetSize( 250, 400 )
	F1Frame:SetTitle( "" )
	F1Frame:SetVisible( true )
	F1Frame:SetDraggable( false )
	F1Frame:ShowCloseButton( true )
	F1Frame:MakePopup()
	F1Frame:Center()
	F1Frame:SetDeleteOnClose( true )
	F1Frame.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 75, 75, 75, 255 ) ) -- Draw the black background

	end
	localply.F1Frame = F1Frame
end

end
usermessage.Hook( “ShadowF1”, ShadowF1Frame )
hook.Add(“ShowHelp”, “ShadowF1”, ShadowF1Frame)

Can you put it in


 tags, its hard to read.