derma menu give player weapon

right i have been looking on google and on facepunch for a way for me to have it so when i click on the button it gives a weapon


function dermaShop()
local ply = LocalPlayer()
local base = vgui.Create( "DFrame" )
local butt = vgui.Create( "DButton" )
	base:SetPos( ScrW()/2 - 225, ScrH()/2 - 100 )
	base:SetSize( 450, 200 )
	base:SetVisible(true)
	base:SetTitle( "Hi Mum" )
	base:SetDraggable(false)
	base:ShowCloseButton(true)
	base:MakePopup()
	
	butt:SetParent( base )
	butt:SetText( "Meow" )
	butt:Center()
	butt:SetSize( 150, 50 )
	butt:SetSize( 150, 50 )
	function butt:DoClick()
	RunConsoleCommand("GiveMeAGun") 
end
end

and i keep getting a error


[ERROR] gamemodes/order/gamemode/init.lua:287: attempt to call method 'Give' (a nil value)
  1. unknown - gamemodes/order/gamemode/init.lua:287
   2. unknown - lua/includes/modules/concommand.lua:54

any ideas on what to do for giving a weapon a gun when the button is clicked?

What’s your serverside code?

concommand.Add(“giveM16”, function (ply, cmd, args)
ply:Give(“weapon_or_flamethrower”)
end)

How? You run GiveMeAGun ConCommand and not giveM16

Either way the problem is that you are calling the :Give function clientside.

sorry i was editing it xD

“concommand.Add(“GiveMeAGun”, function (ply, cmd, args)
ply:Give(“weapon_or_flamethrower”)
end)”

[editline]30th May 2015[/editline]

yes i know that

but even the concommand isnt on the client file but is there a way around this?

any way is there a way i can do this so the player get the weapon when they click on the button

if (SERVER) then
concommand.Add(“GiveMeAGun”, function (ply, cmd, args)
ply:Give(“weapon_or_flamethrower”)
end)
end

when clicking the button i get
Unknown command: GiveMeAGun

Your console command must be created in a serverside or shared file.

gamemodes/order/gamemode/init.lua will do.

its in my shared

i still get it

Your shared is not included from init.lua

shared.lua



if (SERVER) then
concommand.Add("GiveMeAGun", function (ply, cmd, args)
ply:Give("weapon_or_flamethrower")
end)
end


cl_init.lua



include( 'shared.lua' )
include( 'sh_init.lua' )

function dermaShop()
local ply = LocalPlayer()
local base = vgui.Create( "DFrame" )
local butt = vgui.Create( "DButton" )
	base:SetPos( ScrW()/2 - 225, ScrH()/2 - 100 )
	base:SetSize( 450, 200 )
	base:SetVisible(true)
	base:SetTitle( "Hi Mum" )
	base:SetDraggable(false)
	base:ShowCloseButton(true)
	base:MakePopup()
	
	butt:SetParent( base )
	butt:SetText( "Meow" )
	butt:Center()
	butt:SetSize( 150, 50 )
	function butt:DoClick()
	RunConsoleCommand("GiveMeAGun")
end
end


usermessage.Hook( "Openplz", dermaShop )


init.lua



AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( 'shared.lua' )

function GM:PlayerButtonDown( ply, key )
if (key == 13) then
		umsg.Start( "Openplz", ply )
		umsg.End()
end
end


Does it still print the Lua error? Does it print “unknown command”? Have you restarted your game?

so i did this and it worked xD

if (SERVER) then
concommand.Add(“GiveMeAGun”, function (ply, cmd, args)
ply:Give(“weapon_or_flamethrower”)
ply:PrintMessage( HUD_PRINTTALK, “You got the FlameThrower” )
end)
end