Custom HUD problem

So yah, since im tired of seeing that old HL2 HUD i decided to make my personal one, but I need help to fix something. So the HUD works, everything is fine, exept for one thing, when I die, an error occurs and my HUD disappears and never comes back until I reconnect.
I will show you the Code.

[lua]
good_hud = { };
local function clr( color ) return color.r, color.g, color.b, color.a; end

function good_hud:PaintBar( x, y, w, h, colors, value )
self:PaintPanel( x, y, w, h, colors );
x = x + 1; y = y + 1;
w = w - 2; h = h - 2;
local width = w * math.Clamp( value, 0, 1 );
local shade = 4;
surface.SetDrawColor( clr( colors.shade ) );
surface.DrawRect( x, y, width, shade );
surface.SetDrawColor( clr( colors.fill ) );
surface.DrawRect( x, y + shade, width, h - shade );
end

function good_hud:PaintPanel( x, y, w, h, colors )
surface.SetDrawColor( clr( colors.border ) );
surface.DrawOutlinedRect( x, y, w, h );
x = x + 1; y = y + 1;
w = w - 2; h = h - 2;
surface.SetDrawColor( clr( colors.background ) );
surface.DrawRect( x, y, w, h );
end

function good_hud:PaintText( x, y, text, font, colors )
surface.SetFont( font );
surface.SetTextPos( x + 1, y + 1 );
surface.SetTextColor( clr( colors.shadow ) );
surface.DrawText( text );
surface.SetTextPos( x, y );
surface.SetTextColor( clr( colors.text ) );
surface.DrawText( text );
end

function good_hud:TextSize( text, font )
surface.SetFont( font );
return surface.GetTextSize( text );
end

local vars =
{ };

local colors =
{ };

local function HUDPaint( )

end
hook.Add( “HUDPaint”, “PaintOurHud”, HUDPaint );

local vars =
{

font = "TargetID",

padding = 10,
margin = 35,

text_spacing = 2,
bar_spacing = 5,

bar_height = 16,

width = 0.25

};

local colors =
{

background =
{

	border = Color( 0, 0, 0, 0 ),
	background = Color( 0, 0, 0, 0 )

},

text =
{

	shadow = Color( 0, 0, 0, 200 ),
	text = Color( 255, 255, 255, 255 )

},

health_bar =
{

	border = Color( 255, 255, 255, 255 ),
	background = Color( 0, 195, 255, 75 ),
	shade = Color( 180, 200, 255, 255 ),
	fill = Color( 0, 195, 255, 255 )

},

suit_bar =
{

	border = Color( 255, 255, 255, 255 ),
	background = Color( 0, 135, 255, 75 ),
	shade = Color( 180, 150, 255, 255 ),
	fill = Color( 0, 135, 255, 255 )

}

};

local function HUDPaint( )
client = client or LocalPlayer( ); – set a shortcut to the client
if( !client:Alive( ) ) then return false; end – don’t draw if the client is dead
local _, th = good_hud:TextSize( “TEXT”, vars.font ); – get text size( height in this case )
local i = 2; – shortcut to how many items( bars + text ) we have
local width = vars.width * ScrW( ); – calculate width
local bar_width = width - ( vars.padding * i ); – calculate bar width and element height
local height = ( vars.padding * i ) + ( th * i ) + ( vars.text_spacing * i ) + ( vars.bar_height * i ) + vars.bar_spacing;
local x = vars.margin;
local y = ScrH( ) - vars.margin - height; – get y position of element
local cx = x + vars.padding; – get x and y of contents
local cy = y + vars.padding;
good_hud:PaintPanel( x, y, width, height, colors.background ); – paint the background panel
local by = th + vars.text_spacing; – calc text position
local text = string.format( “Health Points: %i HP”, client:Health( ) ); – get health text
good_hud:PaintText( cx, cy, text, vars.font, colors.text ); – paint health text and health bar
good_hud:PaintBar( cx, cy + by, bar_width, vars.bar_height, colors.health_bar, client:Health( ) / 100 );
by = by + vars.bar_height + vars.bar_spacing; – increment text position
local text = string.format( “Armor Points: %i AP”, client:Armor( ) ); – get suit text
good_hud:PaintText( cx, cy + by, text, vars.font, colors.text ); – paint suit text and suit bar
good_hud:PaintBar( cx, cy + by + th + vars.text_spacing, bar_width, vars.bar_height, colors.suit_bar, client:Armor( ) / 100 );

client = client or LocalPlayer( );
local _, th2 = good_hud:TextSize( “TEXT”, vars.font );
local i2 = 2;
local width2 = vars.width * ScrW( );
local bar_width2 = width2 - ( vars.padding * i2 );
local height2 = ( vars.padding * i2 ) + ( th2 * i2 ) + ( vars.text_spacing * i2 ) + ( vars.bar_height * i2 ) + vars.bar_spacing;
local x2 = vars.margin * 20.85;
local y2 = ScrH( ) - vars.margin - height2;
local cx2 = x2 + vars.padding;
local cy2 = y2 + vars.padding;
good_hud:PaintPanel( x2, y2, width2, height2, colors.background );
local by = th2 + vars.text_spacing;
local text = string.format( “Primary Clip: %i Left”, client:GetActiveWeapon():Clip1() );
good_hud:PaintText( cx2, cy2, text, vars.font, colors.text );
good_hud:PaintBar( cx2, cy2 + by, bar_width2, vars.bar_height, colors.health_bar, client:GetActiveWeapon():Clip1() / client:GetAmmoCount() );
by = by + vars.bar_height + vars.bar_spacing;
local text = string.format( “Secondary Ammo: %i Left”, client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()))
good_hud:PaintText( cx2, cy2 + by, text, vars.font, colors.text );
good_hud:PaintBar( cx2, cy2 + by + th2 + vars.text_spacing, bar_width2, vars.bar_height, colors.suit_bar, client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) / client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()))
end

hook.Add( “HUDPaint”, “PaintOurHud”, HUDPaint );

function hidehud(name)
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)
[/lua]

So the error occurs on line 143 and 147, where the HUD gets the client’s ammo. When I die, since there is no more ammo to get, the error occurs, and my HUD dosen’t come back.

Can someone Help me with this code and try fixing it for me please, I would really appreciate.
Thank You.

Simply do a check.
[lua]if client:GetActiveWeapon() then
–Display ammo the regular way
else
–Display : No Ammo(or something)
end[/lua]

Alright, I’ll make some tests to see if I can get it working using your check, if I don’t then I’ll come back to you.

Ok perfect I got it working, Thanks.