HUD Health Bar Issue

So I am trying to replicate Skyrim’s health bar from the hud yet I am having issues. I am trying to get the health to depleat from either end and it only works for either the x position or the width size as I am trying to get the xpostion + player health, width - player health.

Here is the code…

[lua]
local barb = Material(“skyrimhud/barb.png”)
local health = Material(“skyrimhud/health.png”)
local stamina = Material(“skyrimhud/stamina.png”)

local bw = ScrW() * 0.2239 --430
local bh = ScrH() * 0.0277 --30
local hw = ScrW() * 0.1927 --370
local hh = ScrH() * 0.0185 --20
local sw = ScrW() * 0.1927 --370
local sh = ScrH() * 0.0185 --20

local function DrawHUD()

local healthply = LocalPlayer():Health() / 100

local staminaply = LocalPlayer():getDarkRPVar("Stamina")   

--so it doesn't draw invisible
surface.SetDrawColor(255,255,255)  

--draw health background
surface.SetMaterial(barb)
surface.DrawTexturedRect((ScrW() /2) - bw / 2 ,ScrH() * 0.9,bw,bh)

--draw health bar
if healthply != 0 then
    surface.SetMaterial(health)
    surface.DrawTexturedRect((ScrW() / 2) - hw + ScrW() * 0.3860 / 2 -(hw / 2 * healthply) ,(ScrH() * 0.9) + hh/4, hw/2+(hw/2*healthply),hh)
    print(healthply*100)
end

--draw stamina background
surface.SetMaterial(barb)
surface.DrawTexturedRect((ScrW() /1.245) - bw / 2 ,ScrH() * 0.9,bw,bh)

--draw stamina bar
surface.SetMaterial(stamina)
surface.DrawTexturedRect((ScrW() /1.245) - sw / 2 ,(ScrH() * 0.9) + sh/4, sw,sh)

draw.RoundedBox(0,5,875,300,200,Color(102,102,102))

end

hook.Add(“HUDPaint” , “Skyrimhud” , DrawHUD)
[/lua]

It’s on line 28 and I am very confused so goodluck :stuck_out_tongue:

Thanks for any help, it’s probably me being stupid and overlooking something simple.