Calling v:GetActiveWeapon( ):GetPrintName(). Getting nil.

Title says all. I even have a check to see if it will be nil, but for some reason, when it tries to call it to see if it’s nil, it screws up :P. Is there any better way to do this? (Yes, it’s a clientside script)

[lua]if (v:GetActiveWeapon( ):GetPrintName()) == nil then
draw.DrawText(“None”, “ScoreboardText”, pos.x, pos.y, Color(255,255,0,255),1)
elseif !(v:GetActiveWeapon():GetTable().PrintName) == nil then
draw.DrawText((v:GetActiveWeapon( ):GetPrintName()), “ScoreboardText”, pos.x, pos.y, Color(255,255,0,255),1)
end[/lua]

You need to check if the player has a weapon before trying to get the print name.

[lua]if v:GetActiveWeapon() and v:GetActiveWeapon():GetPrintName() then
– rest of your code
end[/lua]

AAH, I wish I could think of these things myself… Thank you so much.

[editline]10:58AM[/editline]

Hmm, well I’m still getting this error:


ERROR: Hook 'Paint' Failed: lua\autorun\client\gat.lua:117: attempt to call method 'GetPrintName' (a nil value)
Removing Hook 'Paint'

This is my code:
[lua]if v:GetActiveWeapon() and v:GetActiveWeapon():GetPrintName() then
draw.DrawText((v:GetActiveWeapon( ):GetPrintName()), “ScoreboardText”, pos.x, pos.y, Color(255,255,0,255),1)
else
draw.DrawText(“None”, “ScoreboardText”, pos.x, pos.y, Color(255,255,0,255),1)
end[/lua]
[editline]11:17AM[/editline]

Changed v:GetActiveWeapon() to v:GetActiveWeapon():IsValid(). Works now. Thanks.