I am creating a script that applies damage to the player but I have a problem.
the player may or may not have a shield which is stored in an intvalue I am applying the damage to the shield but if the damage exceeds the amount of the shield the value becomes negative
How do I get it to detect when the shield reaches 0 and apply the remaining damage to the player’s life?
I know that I have to apply the damage progressively to be able to detect when it reaches 0 but I am worried that using a for loop will delay the game
All you need to do is when the damage event runs check if the shield is less than or = to 0 and if it is then instead of damaging the shield, you would damage the character, for example,
-- you would put this in your damage script, so everytime the character gets damage, it checks if the shield is at 0 or less.
if Shield.Value <= 0 then
Humanoid:TakeDamage(--Amount)
end
--never tested this out but maybe it works
humanoid:TakeDamage(math.max(0, damageTaken-shield.Value))
shield.Value = math.max(0, shield.Value-damageTaken)