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

How would I make this for loop do the exact opposite of what its doing now?

I got this code from another answer, and I need it to do the exact opposite of what it's doing now and I'm confused: go from the transparency of 1 to 0 instead of the other way around!

  • this is for a GUI by the way...
for i = 0, 1.05, 0.05 do
script.Parent.Frame.TextLabel.TextTransparency = i -- fades the gui out right now
wait(0.01)
end

I tried a bunch of combinations without any luck :(

1 comment

0

You can also do (assume x > y), for i = x, y do a.Transparency = (x - i) end, subtract i from x

3 answers

✓ Accepted answer

Its simple Here is a example of For loop makes: for iterator_variable = start value , end value , increment do, And add - before increment number to make this remove. examples of for loop:

for i = 1, 0, -0.05 do -- Makes the number 1 to 0 with removing 0.05 per 0.01 seconds.
	script.Parent.Frame.TextLabel.TextTransparency = i
	wait(0.01) -- Time for wait to adding/removing.
end

for i = 1, 0, -0.1 do -- Makes the number 1 to 0 with removing 0.1 per 0.1 seconds.
	script.Parent.Frame.TextLabel.TextTransparency = i
	wait(0.1) -- Time for wait to adding/removing.
end

What for loop make? Image

What is for loop

The for loop is a way of running a command or set of commands a set number of times.

Hope it helped

You can see more in wiki: For loop


Solved your problems? put in title [SOLVED] or accept a answer.

So if you read over on the wiki page for for-loops you'll find that you can subtract or count down with the for-loop by simply making the iterator negative.

From going 1 down to 0 would look like:

for i = 1, 0, -.1 do
	script.Parent.Frame.TextLabel.TextTransparency = i

	wait(1)
end

This would fade TextTransparency to 0 or make it visible. Our step is '.1' and a time interval of 1 second so the fade will take some time to become visible. You would need to mess with these to get a reasonable effect.

Know that this for-loop example is actually adding '-0.1' to the iterator variable.

Fairly simple, just add an - infront of 1.05 and 0.05

(I tested this in studio so I know it works)

for i = 0, -1.05, -0.05 do
	script.Parent.Frame.Transparency = i -- fades the gui out right now
	wait(0.01)
end		

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