So I am currently working on polishing up a hud that I just finished. Now the only problem I can't manage to fix, is the fact that whenever a player dies, the ply:GetActiveWeapon() prints out a nil value due to the fact that the player is dead, so there is no active weapon, which results in an error.
I have been trying to counter this with an " ply:Alive() " or currently
[code]
if ( ply:GetActiveWeapon() == nil ) == false then
[/code]
but nothing seems to really work. Or maybe I am just doing it wrong? Well I don't know and i've been looking for a solution for quite a bit of time now.
I am looking for a method to filter out a nil value while say the player is dead, or overall if the value of something is nil, then it simply won't try to run itself.
GetActiveWeapon doesn't return nil when the player is dead, it returns NULL. You can check this with:
[code]if (ply:GetActiveWeapon():IsValid()) then[/code]
Also, you should localise GetActiveWeapon's return if you are going to be using it more than once.
[QUOTE=code_gs;52172155]GetActiveWeapon doesn't return nil when the player is dead, it returns NULL. You can check this with:
[code]if (ply:GetActiveWeapon():IsValid()) then[/code]
Also, you should localise GetActiveWeapon's return if you are going to be using it more than once.[/QUOTE]
Thank you very much, I was actually trying to use IsValid at one point, but clearly I wasn't doing it properly.
Also I am localising it, just after the validity check.:downs:
Localise it before so you don't have to call it twice.
Sorry, you need to Log In to post a reply to this thread.