Need help with my vertical Hunger bar

As the title saids i have an issue with my hud at the moment where it gives me this error. Which i do not understand because my vertical health/armor bar works fine.

the error:



[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/fadeouthud/cl_hud.lua:25: attempt to perform arithmetic on a nil value
  1. HUDHunger - addons/darkrpmodification-master/lua/darkrp_modules/fadeouthud/cl_hud.lua:25
   2. v - addons/darkrpmodification-master/lua/darkrp_modules/fadeouthud/cl_hud.lua:35
    3. unknown - lua/includes/modules/hook.lua:84


My code by far:



local Settings = {}

local function HUDHealth()
  local ply = LocalPlayer()

  -- Health
  draw.RoundedBox(0, 10+102, 10+100 - ply:Health() * 0.47 , 40, ply:Health() * 0.47, Color( 255, 0, 0, 200 ))
  draw.SimpleText(ply:Health(), "TargetID", 10+122, 10+75, Color( 255, 255, 255, 250 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

end

local function HUDArmor()
  local ply = LocalPlayer()

  -- Armor
  draw.RoundedBox(0, 10+144, 10+100 - ply:Armor() * 0.47 , 40, ply:Armor() * 0.47, Color( 0, 0, 255, 200 ))
  draw.SimpleText(ply:Armor(), "TargetID", 10+164, 10+75, Color( 255, 255, 255, 250 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end


local function HUDHunger()
  local ply = LocalPlayer()

  -- Hunger
  draw.RoundedBox(0, 10+186, 10+100 - ply:getDarkRPVar( "energy" ) * 0.47 , 40, ply:getDarkRPVar( "energy" ) * 0.47, Color( 0, 255, 0, 200 ))
  draw.SimpleText(ply:getDarkRPVar( "Energy" ), "TargetID", 10+204, 10+75, Color( 255, 255, 255, 250 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

end

local function FadeoutHUD_Paint()

  -- Custom
  HUDHealth()
  HUDArmor()
  HUDHunger()

end
hook.Add( "HUDPaint", "FadeoutHUD_Paint", FadeoutHUD_Paint )



Here is what i want the hunger bar to do. (Go vertical down)

You need to capitalize the E in energy on line 25.

ply:getDarkRPVar( “energy” ) is returning nil so you can’t perform arithmetic operations(calculus/math) on it.

It’s not set (yet)

On the next line you write energy with a capital E, did you mean to write that on the line before as well?

I changed that and it didn’t help.

How do i set it then?
Also i actually wanted to type with capital E on both lines.

EDIT:
Nevermind i just had to reload. So thank you moat and joker :slight_smile: