I saw someone doing a boss fight game and they made 21 costumes for the health bar. I knew there was a more efficient way. There's probably one even more efficient than this, but this is at least more efficient than the costumes way.
v2: Now smoother, added some different color schemes, updates instantly and no longer breaks when the HP changes too fast.