First, it's crashing because you're cyclically transitioning through three states when out of ammo - Ready to PreFire to StopFire, repeat. Second, put a stateTransitionOnNoAmmo in fire, too, so it goes to stopFire when you run out. Third, consider adding onStopFire and onPreFire scripts that check if the energy is less or greater than an arbitrary value, like 10 percent, and if so, toggles the ammo accordingly. This will make it so if your energy runs below it, you can keep firing until you let go of the trigger (Because fire only loops through itself, not through stop/preFire) or run out of energy, at which point you'll have to recharge back up to that value before you can use it again.