attempt to call method 'PrintMessage' (a nil value)

Hello, I am getting the error “attempt to call method ‘PrintMessage’ (a nil value)” when I am running my script.

if SERVER then

	function WeaponEquip(wpn)

	local foundWeapon = false
	local ply = wpn:GetOwner()
	for i=1,20 do
		if wpn:GetClass() == RestrictedWeapons*.Name then
			foundWeapon = true
		if foundWeapon == true then
			ply:PrintMessage( HUD_PRINTTALK, "[AMod] Sorry, you need a higher rank to carry this weapon.")
	hook.Add( "WeaponEquip", "PlayerWeaponEquip", WeaponEquip )

Your help is appreciated, thanks :slight_smile:

You’re not defining what ply is, edit your function WeaponEquip (wpn) with, function WeaponEquip (wpn, ply )

Thanks :slight_smile:


Edit: Changed it, still getting the same error :confused:


Your dumb… Also OP, I can’t see what the problem is atm, I’ll just quick test it.

OP read the notes here: **[Gamemode.WeaponEquip](**

Or if your lazy: *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. *