• attempt to call method 'PrintMessage' (a nil value)
    4 replies, posted
Hello, I am getting the error "attempt to call method 'PrintMessage' (a nil value)" when I am running my script. [code] if SERVER then function WeaponEquip(wpn) local foundWeapon = false local ply = wpn:GetOwner() for i=1,20 do if wpn:GetClass() == RestrictedWeapons[i].Name then foundWeapon = true wpn:Remove() end end if foundWeapon == true then ply:PrintMessage( HUD_PRINTTALK, "[AMod] Sorry, you need a higher rank to carry this weapon.") end end hook.Add( "WeaponEquip", "PlayerWeaponEquip", WeaponEquip ) end [/code] Your help is appreciated, thanks :)
You're not defining what ply is, edit your function WeaponEquip (wpn) with, function WeaponEquip (wpn, ply )
[QUOTE=Smellyzarg;25225885]You're not defining what ply is, edit your function WeaponEquip (wpn) with, function WeaponEquip (wpn, ply )[/QUOTE] Thanks :) [editline]05:30PM[/editline] Edit: Changed it, still getting the same error :/
-snip-
[QUOTE=Smellyzarg;25225885]You're not defining what ply is, edit your function WeaponEquip (wpn) with, function WeaponEquip (wpn, ply )[/QUOTE] Your dumb.. Also OP, I can't see what the problem is atm, I'll just quick test it. [B]Edit:[/B] OP read the notes here: [b][url=wiki.garrysmod.com/?title=Gamemode.WeaponEquip]Gamemode.WeaponEquip [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Or if your lazy: [I]At the time this hook is called, the weapon doesn't have an owner. wep:GetOwner will return a Null Entity. The Weapon Owner is set on the next frame. I found it easiest to use timer.Simple to get around this problem. As shown in the example above. [/I]
Sorry, you need to Log In to post a reply to this thread.