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

Question for shawnyg?

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.

3 comments

0

0.9 is 90 percent. And shawny is correct, can't multiply a word by a number!

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.

0

cuz shawny is an intelligent man

2 answers

✓ Accepted answer

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

2 comments

0

Since * 0.9 is the same as -10%, the decimal problem is still there. And how it repeats isnt relevant.

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

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

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