#General 'for loop' Explanation
###Syntax of 'for' loop:
for Variable = Start, End, Increment do
end
The 'for' loop will allow you to do exactly what you require. What it does is it takes three arguments (must be integers), a start, end, and increment. 'start' is where the loop will begin, 'end' is where it will stop, and 'increment' is the step-value. Start will be the first argument, End will be the second, and Increment will be the third. If you don't set Increment, it will default to 1.
Note: 'Variable' can be set to anything.
##Example
for i=1,7,1 do
print("Hello world!")
end
###Output:
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
What that did is it printed 'Hello world!' 7 times, the exact same value as 'End', now if I were to change 'Increment' to 2, it would only print 3 times. The reason for this is that as the loop runs, it's not increasing by 1, but 2. So for instance, It would go 1, 3, 5, 7, rather than 1 to 7.
Each time this ran, the code within the loop ran, and every time, 'Variable' was increased by 'Increment'
Start, End, and Increment can be set to any value, even negative, though if you set 'Start' to any value higher than 'End', the loop will not run without setting 'Increment' to a negative value.
#Generic 'for': in pairs
Another 'for' loop type is 'in pairs', this type will iterate through a table of objects
###Syntax
for Position,Value in pairs(Table) do
end
In this loop type, it will run the code for every object passed, 'Value'. 'Position' works just like 'Variable' in the previous example. 'Table' is a table of objects to iterate through. This type of 'for' loop does not use increments, it loops through each and every item inside 'Table'. This type of for loop would be useful for running code for multiple objects.
##Example using your own.
for i,v in pairs(ListOfFrames)
local frame = script.Parent.IntroFrame1.Box1
for i=0,20,5 do
frame:TweenSizeAndPosition(UDim2.new(0,5,0,5),UDim2.new(.5,i,.3,145+i)
wait(.5)
end
for i=0,1,.1 do
frame.BackgroundTransparency=i
wait()
end
frame:Destroy()
end
ListOfFrames should be a table of all 'Frames' you want to run code for.
In the first 'for' loop, each time the loop ran the code, the X-Offset was set to the current position in the loop, i, and Y-Offset was set to 145 + the current position.
In the second 'for' loop, each time the loop ran, it set 'BackgroundTransparency' to the current position in the loop.
8 comments
Code Block Please!
i did
There is a Shorter way of making your Frame Transparent.
really?!
wait isn't that the i, 10 loop thing
for i=.1, 0, +.1 do I think.
so did you figure it out, how to make my life easier.
i'll give you guys 5 mins then ill just keep changing the position... Please don't let me do it.