How to make health bar go downward when hp is lost?

Hello everyone! I have a question I would like to ask…
I was making an attempt at coding an HUD, but I don’t know how to make it so that the health bar goes downward when I lose hp, here’s an image:

My HP in this image is at 50, but I want it so that the health bar goes downward, instead of upward when I lose HP, any help?

Thank you.

[editline]28th July 2015[/editline]

bump, please help




local height = 500 -- This is the height of the RED bar
local maxHeight = 1000 -- This is the height of the black bar

local y = math.floor( ScrH() / 2 ) -- This is the Y position of the BLACK bar. 
local y2 = y + maxHeight - height -- This is the Y position for the RED bar



Should work.

Thank you so much man :slight_smile:

Sorry, it didn’t work. Here’s the code for the health bar if it helps… Or did I place it in the incorrect place? ( Sorry, im new to coding)


	draw.RoundedBox(10, ScrW() - 1138 - 10, ScrH () - 115 - 10, 30, 120, Color(0, 0, 0, 245))
	
	local DrawHealth = LocalPlayer():Health() or 0
	local EchoHealth = LocalPlayer():Health() or 0
	
	if DrawHealth > 100 then DrawHealth = 100 end
	if DrawHealth < 10 then DrawHealth = 10 end
	
	if DrawHealth != 0 then
		draw.RoundedBox(10, ScrW() - 1138 - 10, ScrH () - 115 - 10, 30, (120) * DrawHealth / 100 , Color(255, 0, 0, 245))	
	end

Bump

Did you just bump by a 4 hour diffrence?

What file did you place it in? Also if the HUD isn’t showing up then its probably the right file. Not to mention try not using the coding beasts EXACT work for this. During the video I recommend stopping then making your own local variables, or something similar to that. It will help you learn more.


	draw.RoundedBox(10, ScrW() - 1138 - 10, ScrH () - 115 - 10, 30, 120, Color(0, 0, 0, 245))
	
	local DrawHealth = LocalPlayer():Health() or 0
	local EchoHealth = LocalPlayer():Health() or 0
	
	if DrawHealth > 100 then DrawHealth = 100 end
	if DrawHealth < 10 then DrawHealth = 10 end
	
	if DrawHealth != 0 then
		draw.RoundedBox(10, ScrW() - 1138 - 10 + 120, ScrH () - 115 - 10 + 120, 30, 0 - ((120) * DrawHealth / 100) , Color(255, 0, 0, 245))	
	end

To fix it you just have to invert it, beacouse you are placing the start of it up, and the start of it should be DOWN, if you want it to go downward. Also to make it go from up to down you have to put the heigh to negative to go from the initial position to UP.
Also, to fix things with some gamemodes change the part where it divides the health by 100 by diving it by the players max health ( ply:GetMaxHealth() )

[editline]30th July 2015[/editline]

Also, as you can see i changed the heigh from


(120) * DrawHealth / 100

to


0 - ((120) * DrawHealth / 100)

to change it from positive to negative as i said before

[editline]30th July 2015[/editline]

Also, dont fucking bump it in 4 hours.
THIS IS A FORUM, and forums are “slow”.
So please, be patient

[editline]30th July 2015[/editline]

What?

Im saying if he breaks his hud file then the hud wont show up. Generally speaking he did it wrong.

It’s working for him. He’s talking about the lua, not the installation.
As you can see its fully functional by the image he has shown