How to terminate a function when something = nil?

I’m making putting ammo on the hud of my gamemode but when you die you get spammed with lua errors because Clip1() = nil. So I tried this but I’m doing it wrong I guess.

[LUA]wep = LocalPlayer():GetActiveWeapon()
Clip = wep:Clip1()
function() if Clip == nil then return false else
local Ammo = LocalPlayer():GetAmmoCount( wep:GetPrimaryAmmoType() )
draw.RoundedBox( 4, (ScrW()/2)+(ScrW()/6.45), (ScrH()/2)+(ScrH()/4)+(ScrH()/4.55), 215, 30, Color(0,0,0,200))
draw.SimpleText(“Ammo: “…tostring(Clip)…”/”…tostring(Ammo)…"", “Font”, (ScrW()/2)+(ScrW()/6), (ScrH()/2)+(ScrH()/4)+(ScrH()/4.5))
end[/LUA]

Please help, thanks in advance.

Add a check to see if the player is alive, and also do a check to see if the weapon exists before doing your hud work.
[lua]
LocalPlayer():IsAlive()
wep != nil
[/lua]

sorry for being a noob, but I tried this and its still giving me the error when I die:

[LUA]if LocalPlayer():Alive() == true then
wep = LocalPlayer():GetActiveWeapon()
if wep == nil then return false else Clip = wep:Clip1() end
local Ammo = LocalPlayer():GetAmmoCount( wep:GetPrimaryAmmoType() )
draw.RoundedBox( 4, (ScrW()/2)+(ScrW()/6.45), (ScrH()/2)+(ScrH()/4)+(ScrH()/4.55), 215, 30, Color(0,0,0,200))
draw.SimpleText(“Ammo: “…tostring(Clip)…”/”…tostring(Ammo)…"", “Font”, (ScrW()/2)+(ScrW()/6), (ScrH()/2)+(ScrH()/4)+(ScrH()/4.5))
end[/LUA]


if not IsValid( wep ) then
  return
end

NULL does not evaluate to false or nil.

That worked thanks for the help!