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

How do I take a percentage out of value?

Hello, I wanna take a percentage out of a value and then add it to another value, The problem is that I don't know how. I searched all over the internet and found only how to get one value from a table with a percentage but thats not what I want.

Help Would Be Really Appreciated

1 comment

0

value1*Percentage/100 + value2

1 answer

In programming, we almost never work with percentages directly. To subtract say, 50% from variable A, you'd do A * 0.5. If we want to "move" 50%, we'll have to subtract half of A from itself, and then "give it" to B.In the example below I declare two doubles (a form of number), print out their values, set A to half its value, and set B to its value plus half of A. Both doubles are then printed again, and at this point will equal 50 and 75 respectively.

local A = 100
local B = 25
print(A, B)
A, B = A * 0.5, B + A * 0.5
print(A, B)

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