How to increase a value by a percentage?

Scenario

Alright, so let’s say BobGaming2000 joins a game. He starts off with a sword that deals 53 damage. Eventually, BobGaming2000 finds a “Strength+” potion that will increase his sword’s damage by 25%. Of course, BobGaming2000 drinks the potion and his sword’s damage is increased by 25%.

Well, actually… it isn’t, because the developer didn’t know how to increase the damage properly because he sucked at math. How would the developer go about fixing his script?

Code
local SwordDamage = 53
local DamageIncrease = 25

SwordDamage += DamageIncrease

When you are increasing a value based on percentage you should be multiplying rather than adding

local SwordDamage = 53
local DamageIncrease = 1.25

SwordDamage = SwordDamage * DamageIncrease 
2 Likes
local SwordDamage = 53
local DamageIncrease = 25

SwordDamage += (SwordDamage*(DamageIncrease/100))

1 Like

@Useful_DoIphin Thanks for this info!

@CZXPEK Thanks for the code example! I’ll be sure to bookmark this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.