I'm trying to test a fan using surface motors, and have it slowly increase from 0% to 100%, taking 10 seconds in total to speed up. My problem is that when I print the ParamB for the motor surface, It leaves something like
0.0099999997764826 0.019999999552965 0.029999999329448 0.03999999910593 0.050000000745058 0.060000002384186 0.070000000298023
instead of
0.01 0.02 0.03 0.04 0.05 0.06 0.07
I am a bit of a perfectionist, so this ticks me off. Here is my code:
script.Parent.TopParamB = 0 while script.Parent.TopParamB < 1 do script.Parent.TopParamB = script.Parent.TopParamB + .01 print(script.Parent.TopParamB) wait(.1) end
This happens because roblox uses floating points.
The way you can get around this is to floor the for loop (use for i=0,100 do
), or use the following.
for i=0,1,0.01 do script.Parent.TopParamB = math.floor(i*100)/100 wait() end
or the floored for loop
for i=0,100 do script.Parent.TopParamB = i/100 wait() end