Unknown Command:

So, I’m trying to make a derma menu where there are two buttons, one giving you a pistol, another, a smg. When I type “lua_openscript weapon_give_derma.lua” in the console, I get an orange error saying Unknown Command: ‘selectweapon’


function GivePlayer(ply,cmd,args)    if args[1] == "pistol" then
        ply:Give("weapon_pistol")
        ply:ChatPrint("You got a pistol!")
    end
    if args[1] == "smg" then
        ply:Give("weapon_smg")
        ply:ChatPrint("You got an SMG!")
    end
end


concommand.Add("weapon_take", GivePlayer)


function WeaponSelector()
local WeaponFrame = vgui.Create("DFrame") --create a frame
WeaponFrame:SetSize(250, 80) --set its size
WeaponFrame:Center() --position it at the center of the screen
WeaponFrame:SetTitle("Take the weapon that you want") --set the title of the menu 
WeaponFrame:SetDraggable(true) --can you move it around
WeaponFrame:SetSizable(false) --can you resize it?
WeaponFrame:ShowCloseButton(true) --can you close it
WeaponFrame:MakePopup() --make it appear
 
local PistolButton = vgui.Create("DButton", WeaponFrame)
PistolButton:SetSize(100, 30)
PistolButton:SetPos(10, 35)
PistolButton:SetText("Pistol")
PistolButton.DoClick = function() RunConsoleCommand("weapon_take", "pistol") WeaponFrame:Close() end --make it run our "weapon_take" console command with "pistol" as the 1st argument and then close the menu
 
local SMGButton = vgui.Create("DButton", WeaponFrame)
SMGButton:SetSize(100, 30)
SMGButton:SetPos(140, 35)
SMGButton:SetText("SMG") --Set the name of the button
SMGButton.DoClick = function() RunConsoleCommand("weapon_take", "smg") WeaponFrame:Close() end
end
 
concommand.Add("selectweapon", WeaponSelector) --make the console command to make this menu popup

Also, some additional information: This is placed in my lua/autorun/client folder. I’m testing it out in singleplayer.

Any help is appreciated.

ply:Give() is serverside, not client

**[Player.Give

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.Give)**

So I placed:
function GivePlayer(ply,cmd,args) if args[1] == “pistol” then
ply:Give(“weapon_pistol”)
ply:ChatPrint(“You got a pistol!”)
end
if args[1] == “smg” then
ply:Give(“weapon_smg”)
ply:ChatPrint(“You got an SMG!”)
end
end

concommand.Add(“weapon_take”, GivePlayer)

in the autorun/server, and the rest of the code in the autorun/client, but I still get the same error. Any advice?

Yes, but make sure your
[lua]ply:Give(“weapon_smg”)[/lua]

becomes
[lua]ply:Give(“weapon_smg1”)[/lua]

That does help me with the smg problem that I didn’t even notice til you pointed it out, but I’m still having that Unknown Command: ‘selectweapon’ problem. I made a .lua file in both client and server, added the top part of the full code to server, other to client, but once i go in singleplayer, type in console: selectweapon, a derma menu is suppose to pop up, but instead the console error pops up.

Did you AddCSLuaFile your clientside script?

No I talked to him, and the problem was that he needed to restart Garry’s Mod.