Numeric for
In a numeric for loop, you provide a start
and finish
range of numbers (with an optional step
variant, that tells you by how much to change the increment variable), to repeatedly execute it's body of code until it's met your destination.
Setting up your range of numbers is done in two ways: Min, Max, (+Step)
or Max, Min, -Step
. Notice the +Step
is in parenthesis, as it's rendered optional
when looping through a range of numbers from Min to Max, whereas looping through Max to Min requires a negative step.
Problem
First of all, in your first for loop, your step is greater than your destination:
1 | for transparency = 0.1 , 0 , 1 do |
2 | script.Parent.Transparency = transparency |
So you're trying to say:
Because of this, your for loop won't even run. It will immediately say "Oh, well we're trying to get to 0, starting at 0.1, but we're adding a positive number each time so this is just going to go on forever... I better not run this"
Now because of how binary calculates floating point numbers, saying something like for i = 1,0,-0.1
isn't entirely accurate. Instead what you should do, is use whole numbers instead, and divide the increment by that whole number to get the 1-0
or 0-1
range. Here's an example:
2 | script.Parent.Transparency = i/ 10 |
That will go from 1, to 10, but only changing the transparency by a difference of 1/10 each time. For doing this backwards (ranging from 1,0), you pretty much do the same process but with a negative step. Here's an example:
2 | script.Parent.Transparency = i/ 10 |
The example above does the same thing as the former, just backwards. Implement this concept in your code, and you should have no problems with floating points numbers or step variants in your numeric for loops! If you have any questions, just let me know.