Functions Not Working Properly?

Hey everyone,

I’ve been trying to code for Garrysmod, you know just basic things but I realized functions aren’t working properly. Everytime I try to put a function over a piece of code it breaks off a certain part. I’ll give an example:

function yes()

local Background = vgui.Create( "DFrame" )
Background:SetPos( 100, 100 )
Background:SetSize( ScrW() - 200, ScrH() - 100 )
Background:SetTitle( "" )
Background:SetVisible( true )
Background:SetDraggable( true )
Background:ShowCloseButton( true )

Website = vgui.Create( "HTML" )
Website:SetPos( 0, 25 )
Website:SetSize( ScrW() - 200, ScrH() - 100 )
Website:OpenURL( "" ) --Example for Facepunch
Website:SetParent( Background )


concommand.Add( "yes", yes )

and I get an error like:

[ERROR] lua/autorun/yes.lua:3: attempt to index global 'vgui' (a nil value)
  1. unknown - lua/autorun/yes.lua:3
   2. unknown - lua/includes/modules/concommand.lua:69

Is the error blue ?
If so, it’s caused by you testing the code on a local server.
Since vgui is clientside and you are trying to draw it serverside.

[lua]if CLIENT then[/lua] right after beginning of the function might fix it.


Nope doesn’t work.

You don’t need a function to run the panel.

didin’t see the command that was added my bad.

The reason I added the function was so that I can initialize it myself with the console command.


if SERVER then return end

to the beginning of the file or move the file to autorun/client.

Putting it in autorun/client worked right away. I don’t know about:

if SERVER then return end

but, eh. Thanks!