• attempt to call method 'Clip1' (a nil value)
    2 replies, posted
Hey guys, I got a lua error on which I'm sitting for days now. I made a HUD with a Ammo Bar and everytime I die, I get this error:  attempt to call method 'Clip1' (a nil value) Now my Code: I hope you have any idea function hudAmmo()   local client = LocalPlayer()   local weapon = LocalPlayer():GetActiveWeapon()   local ammo = weapon:Clip1()   local ammo2 = weapon:GetPrimaryAmmoType()   local ammos = weapon:Clip2()   local ammos2 = weapon:GetSecondaryAmmoType()   if not client:Alive() then return end if (client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end if IsValid(weapon) and ((weapon.GetMaxClip1 and weapon:GetMaxClip1() > 0) or (weapon.GetMaxClip2 and weapon:GetMaxClip2() > 0)) then   if weapon:HasAmmo() then       draw.RoundedBox(4, ScrW() - 190, ScrH() - 88, 170, 60, Color(47, 47, 47, 200))       draw.SimpleText(ammo .. " / " .. LocalPlayer():GetAmmoCount(ammo2), "ammo", ScrW() - 110, ScrH() - 85, Color(152, 152, 152), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)       draw.SimpleText(weapon:GetPrintName(), "namel", ScrW() - 110, ScrH() - 50, Color(152, 152, 152), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)   else     draw.RoundedBox(4, ScrW() - 190, ScrH() - 88, 150, 60, Color(47, 47, 47, 200))     draw.SimpleText(ammo .. " / " .. LocalPlayer():GetAmmoCount(ammo2), "ammo", ScrW() - 110, ScrH() - 85, Color(255, 22, 22), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)     draw.SimpleText(weapon:GetPrintName(), "namel", ScrW() - 110, ScrH() - 50, Color(152, 152, 152), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)   end else end end hook.Add("HUDPaint", "hudAmmo", hudAmmo);
Verify if weapon is valid before create the ammo variable.
uhm... well... I'm stupid, leave me alone please Thanks for your help charozoid, that worked and makes so much sense to me... now :/ But now I got it ^^ Cheers
Sorry, you need to Log In to post a reply to this thread.