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

Question for shawnyg?

Asked by
drew1017 330 Moderation Voter
9 years ago
1decay = decay * 0.9

Trying to make decay go down by 10% repeatedly without making tons of decimals after it goes down a few times.

0
0.9 is 90 percent. And shawny is correct, can't multiply a word by a number! alphawolvess 1784 — 9y
0
How come the question is ONLY for Shawnyg? You can't do that, Once there was a question that was only for BlueTaslem and he himself said that you can't ask certain people to answer your question ONLY. EzraNehemiah_TF2 3552 — 9y
0
cuz shawny is an intelligent man unmiss 337 — 9y

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Well, you'd need to use a loop. Since you have no other code, I recommend you use a while loop!

1decay = 2 -- Make sure to Set the value first!
2 
3while wait(1) do
4    decay = decay - (decay * .10)
5end
0
Since * 0.9 is the same as -10%, the decimal problem is still there. And how it repeats isnt relevant. drew1017 330 — 9y
0
If you want it to be a whole number, you could use math.floor to round down! http://wiki.roblox.com/index.php?title=Math.floor#math.floor Shawnyg 4330 — 9y
Ad
Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

This can take a helluva lot of string manipulation and math, which can cause a helluva lot of frustration. I got it though.

01decay = 10 --Initial value.
02decayfactor = .1 --Rate of decay.
03placesafterdecimal = 3 --Places after decimal.
04 
05while wait(1) do
06    decay = decay - (decay*decayfactor)
07    stringdecay = tostring(decay)
08 
09    if string.find(stringdecay, ".") then
10        local decimal = string.find(stringdecay, ".")
11        local afterdecimal = string.sub(stringdecay, decimal + 2, string.len(stringdecay))
12 
13        if string.len(afterdecimal) > placesafterdecimal then
14            afterdecimal = tostring(math.floor(tonumber(afterdecimal)/10^(string.len(afterdecimal)-placesafterdecimal)))
15        end
View all 24 lines...

Answer this question