title: How do I call a function upon clicking a vgui button
body: <p>(I am fairly new to Lua so please excuse any mistakes I have made trying to explain this) I am trying to make a quest system so that a player can click on a quest when they open an entity and choose to start it. I can't seem to figure out how I can make it so that my &quot;function npcquestkill()&quot; only starts when a player clicks the quest button to start it. The quest button is &quot;local Button = vgui.Create(&quot;DButton&quot;, Frame)&quot;. What could be a way I could go about doing this.</p>
  <pre><code>net.Receive(&quot;OBJ_OPEN&quot;, function()
          local Frame = vgui.Create(&quot;DFrame&quot;)
          Frame:SetPos( 700, 400 ) 
          Frame:SetSize( 500, 350 ) 
          Frame:SetTitle( &quot;Objectives&quot; ) 
          Frame:SetVisible( true ) 
          Frame:SetDraggable( false ) 
          Frame:ShowCloseButton( true ) 
          Frame:MakePopup()
          Frame.Paint = function( self, w, h ) 
              draw.RoundedBox( 0, 0, 0, w, h, Color( 231, 76, 60, 150 ) ) 
          end
  
          local Button = vgui.Create(&quot;DButton&quot;, Frame)
          Button:SetText( &quot;Kill 10 Covenant in One Session&quot; )
          Button:SetTextColor( Color(255,255,255) )
          Button:SetPos( 5, 30 )
          Button:SetSize( 490, 50 )
          Button.Paint = function( self, w, h )
              draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) ) -- Draw a blue button
          end
  
          Button.DoClick = function()
              Button:SetText( &quot;Kill 10 Covenant in One Session: In Progress&quot;)
              vbutton = 2
          end
  
          if (vbutton == 2) then
              Button:SetText( &quot;Kill 10 Covenant in One Session: In Progress&quot;)
          elseif (vbutton == 1) then
              Button:SetText( &quot;Kill 10 Covenant in One Session&quot; )
          end
  end)
  
  function npcquestkill()
      npckills = npckills + 1
      print(npckills)
  end
  
  function rewards(ply)
      if(npckills == 50)then
          ply:AddMoney(1000)
          vbutton = 1
      end
  end
  hook.Add(&quot;OnNPCKilled&quot;,&quot;npcquestkill&quot;, npcquestkill)
  
  </code></pre>