HUD wont update when damage is taken

Hi! I’m having some issues getting my HUD to update. It will update whenever i run the lua script however, i need it to update whenever i take damage!

Help! xD

[LUA]
local HBoxBack = surface.GetTextureID( “hudofwin/hudback” );
local HBox = surface.GetTextureID( “hudofwin/healtharmour” );
local phealth = LocalPlayer():Health()

function PaintHBoxBacK()
local HBoxBackSizeH = 100;
local HBoxBackSizeW = 300;
local client = LocalPlayer();

surface.SetDrawColor( 255, 255, 255, 255 );
surface.SetTexture( HBoxBack );
surface.DrawTexturedRect( 0, (ScrH() * 0.88), HBoxBackSizeW, HBoxBackSizeH );
end

function PaintHBox()
local HBoxSizeH = 48;
local HBoxSizeW = 160;
local client = LocalPlayer();
surface.SetDrawColor( 255, 255, 255, 255 );
surface.SetTexture( HBox );
surface.DrawTexturedRect( 58.5, (ScrH() * 0.921), HBoxSizeW, HBoxSizeH );
end

function PaintABox()
local ABoxSizeH = 48;
//local ABoxSizeW = 160;
local ABoxSizeW = phealth * 1.60
local client = LocalPlayer();
ABoxSizeW = phealth * 1.60
surface.SetDrawColor( 255, 255, 255, 255 );
surface.SetTexture( HBox );
surface.DrawTexturedRect( 58.5, (ScrH() * 0.89), ABoxSizeW, ABoxSizeH );
end

// Draws the users avatar, Crazy inorite?
function DrawAvatar()
local Displayavatar = vgui.Create(“AvatarImage”) // It’s AvatarImage Not Avatar
Displayavatar:SetPos( 225,(ScrH() * 0.905) )
Displayavatar:SetSize( 60, 60 )
Displayavatar:SetPlayer( LocalPlayer() )
end

// Hide the normal hud
function hidehud(name)
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end

DrawAvatar()
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud);
hook.Add( “HUDPaint”, “PaintHBox”, PaintHBox );
hook.Add( “HUDPaint”, “PaintABox”, PaintABox );
hook.Add( “HUDPaint”, “PaintHBoxBacK”, PaintHBoxBacK );[/LUA]

You are setting phealth to the clients health once at the top of the script, this means that it will not update. You need to get the players health every time you want to draw it, just set the health to a local variable in the HUDPaint hook so every time it is run you will get the new health.

Doh V,V Thanks :slight_smile:

No problem.