I actually went for a different approach, since I knew the name of the gun, I used this instead, you just replace WEAPON_M4 by whatever gun you need:
RegisterCommand(‘getgun’, function() weapon = GetHashKey(“WEAPON_M4”) print (weapon) end)