Unknown Console Command, can't figure out why.

So, i was learning LUA with my first tutorials, was about to program a Derma GUI. There you could choose your weapons. I compared multiple scripts, found no mistakes but my GUI will not open using the console command ‘selectweapon’. Here’s my code:


function GivePlayerAWeapon( ply, cmd, args ) -- ply is the player, cmd is the command name (weapon_give), args is the arguments.
		if args[1] == "pistol" then -- if the first argument is "pistol the do the following"
				ply:Give( "weapon_pistol" ) -- gives the player a pistol
				ply:ChatPrint( "You got a pistol" )

concommand.Add( "weapon_take", GivePlayerAWeapon )
concommand.Add( "selectweapon", WeaponSelectorDerma ) -- This console command doesn't work.

My Clientside Stuff for the gui is this:

concommand.Add( "selectweapon", WeaponSelectorDerma ) -- tried to define the console command a second time.
function WeaponSelectorDerma()
SHOPWeaponFrame = vgui.Create( "DFrame" ) -- create a frame.
SHOPWeaponFrame:SetSize( 250, 80 ) -- sets its size.
SHOPWeaponFrame:SetTitle( "Choose your gun and run!" )
SHOPWeaponFrame:SetDraggable( true )
SHOPWeaponFrame:SetSizable( true ) -- can you resize it?
SHOPWeaponFrame:ShowCloseButton( true )

SHOPPistolButton = vgui.Create( "DButton", SHOPWeaponFrame )
SHOPPistolButton:SetSize( 100, 30 )
SHOPPistolButton:SetPos( 10, 35 )
SHOPPistolButton:SetText( "Pistol" )
SHOPPistolButton.DoClick = function() RunConsoleCommand( "weapon_take", "pistol" ) SHOPWeaponFrame:Close() end -- make it run weapon_take in the console with the argument pistol.


Sorry about some comments. These are the rest of explaining myself some LUA stuff.

Maybe it’s just silly mistake, but it would be great if you guys could help me. This is my first GUI and a little bit frustrating that it doesn’t work. I tested other GUIs with the ingame LUA-Pad before and it worked fine? So what’s the Problem?

Thank you! :smiley:

Why are you using concommand.Add serverside on a function that doesn’t exist there (selectweapon)? As for the clientside command, you’re adding it before the function exists.

Thank you so much! It worked! Thanks for the quick response.

I removed concommand.Add from the serverside and put it at the end of the clientside.

Thank you!