Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help me use percentages properly in my script?

I wan't to make it so that the less blood you have, the less damage you deal. If your blood is at 100%, you deal normaI damage. I was thinking of using a percentage to do this.

I was thinking of something like this.

Humanoid:TakeDamage(dmg / %ofblood)

but honestly I don't know how i'd be able to do this. %ofblood would be the current percentage of blood you have, like 20% or 50% of 100%, and dmg would be the damage, humanoid is the player your hitting.

Any and all help is appreciated!

1 answer

✓ Accepted answer
local percentofblood = 100

local damage = 10

local dmg = damage/100 * percentofblood

--Humanoid as in the victim you've hit
Humanoid:TakeDamage(dmg)

Basically what this does, is that it divides it by one hundred, and multiplys it by the percentage of blood. If its 99% of blood, itll become slightly lower. If its 50%, it'll become half. If its 25%, 20% and 10%, it will become 1/4, 1/5, and 1/10 of damage, respectively. Hope this helps!

3 comments

0

I'll test this right now, if it works, i'll happily accept your answer! :)

0

Give me awhile to fully set it up(my damage system is more complex then you might think). If it doesn't work, i'll let you know with an additional comment.

0

Accepted, sorry for taking so long.

This discussion is preserved as it was. New answers, comments, and votes are closed.