self:Give() doesen't work

How come self:Give doesen’t work in a meta function yet ply:Give works in a command defining ply?

It should work, show use the code please.

self isn’t defined I imagine, are you using it in a SWEP, sent, or what? If it’s a SENT, then you would want self.Owner, not just self.

The meta function has to be player function.

function ENT:Think()
local ply = player.GetByID(1)

self:Give( "weapon_smg" ) -- Won't work, cause you're calling it on the entity, and the entity doesn't have a Give function
ply:Give( "weapon_smg" ) -- This will work, cause it's a player object


Then how would I do it apart from a command? Because then it can be abused.

self:ConCommand( "givegun " … gunid … "
" )

[lua]function Give( ply, cmd, args )

ply:Give( args[1] )


local meta = FindMetaTable(“Player”) --I bet this just returns _R.Player

function meta:DoStuff(weaponclass, health)

I’ve already tried making a seperate meta function, and it still doesen’t do anything.

Have you actually tried it?

Have you actually read the thread title?

Apparently you haven’t tried it, I just did.

Guess what happened?

Well for some reason it doesen’t do ANYTHING on my side.

Are you using it in a function?

Post the code.

Yes, if you make a concommand like that it can be abused, but as the coder your job is to make it so that the person can only get anything from the command under the circumstances which you

Why would you use a meta function to give a gun? I’m confused???

What he said. I like to use user messages with console commands and make it look for things. Like say if there buying something from an npc. Make sure there by a npc and the npc is the right npc and not a bank teller or something.

[lua]function GiveWeapon( ply, cmd, args )
if not ply:isSuperAdmin() then return end
Player = player.GetByID( tonumber( args[1] ) )
Player:Give( args[2] )
concommand.Add(“GiveWeapon”, GiveWeapon)[/lua]

Might have errors. Not sure why you wanna use a meta table, this will do perfectly.

local function GiveWeapon( ply, cmd, args )
if not ply:IsSuperAdmin() then return end
local ply = player.GetByID( tonumber( args[1] ) )
ply:Give( args[2] )
concommand.Add(“GiveWeapon”, GiveWeapon)
Always check for errors before ever posting help on this board.

I tried this code on my code but i get this error, any one can help me please ?

autorun\client	est.lua:123: attempt to call method 'Give' (a nil value)

Try running it serverside now

Run it server side…