Inside of a SENT, GetPrintName() gives the error ‘attempt to call method ‘GetPrintName’ (a nil value)’ when the function it is used in is called. The offending line in its entirety is as follows:


Before you ask, yes, activator is defined. A bit of debugging shows that the problem, as stated in the error, lies in GetPrintName() and not GetActiveWeapon() (unless it isn’t meant to be called like that?). Any and all help is appreciated.

Let’s look at your error, what it means is that you the method GetPrintName does not exist on what is returned by activator:GetActiveWeapon().

This happens because activator:GetActiveWeapon() returned something that is not a weapon; You could try printing it but my guess is it returns nil.

This means either one of those things :

  • The player doesn’t actually have an active weapon at the time of calling
  • The player is currently dead
  • The player has no weapons at all
  • The player is in the process of picking up a weapon but has yet to equip it

If knowing that you can’t figure out your problem please post the code creating the error (as in the whole function/hook) so we can assist you further.

No, printing activator:GetActiveWeapon() works perfectly fine (prints something like ‘Weapon[70]’, with a different number for each weapon, it seems). The problem only comes in when I add GetPrintName in. Also, checks have been put in for most of those conditions, and none of them occured during the time of testing.

I’ve found it’s generally more accurate to just use GetActiveWeapon().PrintName.

Seems to return nil, unfortunately.

Are you sure PrintName is defined on the server and client, whichever you’re printing on?

GetPrintName only exists clientside, if you’re doing that code on the server then it won’t work.

Oh darn. That would indeed explain my errors. Thank you.