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
decay = 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!

decay = 2 -- Make sure to Set the value first!

while wait(1) do
    decay = decay - (decay * .10)
end
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.

decay = 10 --Initial value.
decayfactor = .1 --Rate of decay.
placesafterdecimal = 3 --Places after decimal.

while wait(1) do
    decay = decay - (decay*decayfactor)
    stringdecay = tostring(decay)

    if string.find(stringdecay, ".") then
        local decimal = string.find(stringdecay, ".")
        local afterdecimal = string.sub(stringdecay, decimal + 2, string.len(stringdecay))

        if string.len(afterdecimal) > placesafterdecimal then
            afterdecimal = tostring(math.floor(tonumber(afterdecimal)/10^(string.len(afterdecimal)-placesafterdecimal)))
        end

        local beforedecimal = string.sub(stringdecay, 1, decimal)

        local completestring = beforedecimal.."."..afterdecimal
        local completenumber = tonumber(completestring)

        print(completenumber)
    end
end

Answer this question