local frame = script.Parent.IntroFrame1.Box1 wait(.5) frame:TweenSizeAndPosition(UDim2.new(0, 5, 0, 5), UDim2.new(0.5, 5, 0.3, 145)) wait(.5) frame:TweenSizeAndPosition(UDim2.new(0, 5, 0, 5), UDim2.new(0.5, 10, 0.3, 150)) wait(.5) frame:TweenSizeAndPosition(UDim2.new(0, 5, 0, 5), UDim2.new(0.5, 15, 0.3, 155)) wait(.5) frame:TweenSizeAndPosition(UDim2.new(0, 5, 0, 5), UDim2.new(0.5, 20, 0.3, 160)) wait(.5) frame:TweenSizeAndPosition(UDim2.new(0, 5, 0, 5), UDim2.new(0.5, 25, 0.3, 165)) wait(.5) frame.BackgroundTransparency = .1 wait() frame.BackgroundTransparency = .2 wait() frame.BackgroundTransparency = .3 wait() frame.BackgroundTransparency = .4 wait() frame.BackgroundTransparency = .5 wait() frame.BackgroundTransparency = .6 wait() frame.BackgroundTransparency = .7 wait() frame.BackgroundTransparency = .8 wait() frame.BackgroundTransparency = .9 wait() frame.BackgroundTransparency = 1 wait() frame:remove()
I don't really want to keep copying and changing the position of the boxes each time it will take me forever so can you guys teach me how to do it with out keep changing the position by 5 each time please.
Thank you!
for Variable = Start, End, Increment do -- Code 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.
for i=1,7,1 do print("Hello world!") end
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.
Another 'for' loop type is 'in pairs', this type will iterate through a table of objects
for Position,Value in pairs(Table) do -- Code 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.
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() --Remove is deprecated and should not be used 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.