Adding multiple bars of health with damage that carries over?

local damage = 75

local bar1Damage = math.min(Humanoid.Values.Armor.Value, damage);
local bar2Damage = math.min(Humanoid.Values.Life.Value, damage - bar1Damage);

Humanoid.Values.Armor.Value -= bar1Damage;
Humanoid.Values.Life.Value -= bar2Damage;

Using this code I was able to make it so when you take damage that depletes the armor bar below 0, the leftover damage is applied to the life bar, but how would I go about creating more than just one extra life bar? I want to be able to have layered life bars so when one depletes, the next one starts depleting, and any damage that exceeds the depleted bar is carried over to the next one. Or if more than one bar is depleted in a single attack, the damage is still carried over accordingly. Can’t seem to make this work with more than two life bars.

If all you need is multiple overlapping life bars, and they all have the same life pool (no bar is different from another other than its color), then you may just have one single life pool, and have each life bar be a section of that life pool.

So if you had 100 health and 4 life bars: red, orange, yellow and green, then green would start depleting first and be gone at 75 hp, yellow would follow until 50 etc.

Then it might happen that you are at 60 life and get hit for 40. All you need to do is calculate which health bar is at 20 hp (60-40), which is red, then set red to 80% (20/25), hide all bars above it and show all bars below it (red has nothing below it, of course)

I could never get a single life pool to work, but found a working solution involving giving each bar it’s own value of hitpoints and finding the value to carry to the next bar based on how much damage the last bar that was damaged took. All the bars are layered from 1 to 20 so I can manage them in the proper order they appear. The code that expands or depletes the bars is in a different script and doesn’t rely on the damage values, just expands or depletes each given bar depending on how much of it is left, and since the damage will always apply in the chronological order of each layered bar it all works out.

1 Like