So, i was watching a tutorial on how to make a health bar byd123s404 on YouTube and I finished the tutorial only to come out to a problem. My health bar has to take damage at least once before it moves, the actual health bar moves only when the ghostHP is changed. I have posted the code below. When I run the game the console shows no errors.
import bge
def main():
cont = bge.logic.getCurrentController()
healthBar = cont.owner
space = cont.sensors['Keyboard']
percHP = healthBar['hp'] / healthBar['maxHP'] * 100
percGhostHP = healthBar['ghostHP'] / healthBar['maxHP'] * 100
healthBar['animHP'] = percHP * 10
healthBar['animGhostHP'] = percGhostHP * 10
if space.positive:
healthBar['ghostHP'] = healthBar['hp']
healthBar['hp'] = healthBar['hp'] - 30
healthBar.playAction("HealthBarAnimation", healthBar['animGhostHP'], healthBar['animHP'], play_mode= bge.logic.KX_ACTION_MODE_PLAY, speed = 30.0)
main()