Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I need help with my script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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!

0
Code Block Please! woodengop 1134 — 9y
0
i did Ewarr1011 0 — 9y
0
There is a Shorter way of making your Frame Transparent. woodengop 1134 — 9y
0
really?! Ewarr1011 0 — 9y
View all comments (4 more)
0
wait isn't that the i, 10 loop thing Ewarr1011 0 — 9y
0
for i=.1, 0, +.1 do I think. woodengop 1134 — 9y
0
so did you figure it out, how to make my life easier. Ewarr1011 0 — 9y
0
i'll give you guys 5 mins then ill just keep changing the position... Please don't let me do it. Ewarr1011 0 — 9y

1 answer

Log in to vote
2
Answered by
Muoshuu 580 Moderation Voter
9 years ago

General 'for loop' Explanation


Syntax of 'for' loop:

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.


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
    -- 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.


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() --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.

0
dude i have 30 boxes that i want to move not only one( i don't know if this function is possible). Ewarr1011 0 — 9y
0
Edited. Muoshuu 580 — 9y
0
i have a question about for i=1,7,1 do... what does the last 1 mean i get 1,7 but i don't get why you need the last 1? Ewarr1011 0 — 9y
0
The last one is not required, though useful, it is explained after the 'Hello world!' output. Muoshuu 580 — 9y
0
The code doesn't work, line 2. Ewarr1011 0 — 9y
Ad

Answer this question