+Always
->Set playerhealthbar.width to
clamp(playerhealthbar.width - 1, (player.value('health') / 100) * playerhealthbar.value('maxwidth'), playerhealthbar.value('maxwidth'))
--
This will always set hpbar.width-1 every ticks.
But if you only set this the hpbar will decrease continuously. So use the clamp to set the max and min hpbar.width value.
Clamp(Value, Lower bound, Upper bound)
Lower bound = hpbar.width you want it to be. You change this value the hpbar.width will -1 until this value. And hpbar.width-1 will stop when hpbar.width hit this value. This value is controlled by player health.
Player get damaged -> the lower bound changed -> hpbar.width start to decrease.