Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can someone help me use percentages properly in my script?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
RAFA1608 543 Moderation Voter
4 years ago
Edited 4 years ago
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!

0
I'll test this right now, if it works, i'll happily accept your answer! :) ErskinePierre 48 — 4y
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. ErskinePierre 48 — 4y
0
Accepted, sorry for taking so long. ErskinePierre 48 — 4y
Ad

Answer this question