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

What's a better way of doing this?

Asked by 9 years ago

I find changing the transparency of a frame by doing this is not efficient at all.. I'm trying to create a fade effect but I heard there is something easier to do this with less lines of code.

And how would I do the same thing to multiple frames at once?

Example of bad code


Frame.Transparency = 0.1 wait(0.1) Frame.Transparency = 0.2 wait(0.1) Frame.Transparency = 0.3 wait(0.1) Frame.Transparency = 0.4 wait(0.1) Frame.Transparency = 0.5 wait(0.1) Frame.Transparency = 0.6 wait(0.1) Frame.Transparency = 0.7 wait(0.1) Frame.Transparency = 0.8 wait(0.1) Frame.Transparency = 0.9

2 answers

Log in to vote
1
Answered by
Vividex 162
9 years ago

In Lua, there are many different kind of loops, repeats, while, and for loops, and for this, the best choice would be a for loop. You also need to recognize where frame is from.. I'm thinking thats in StarterGui in a ScreenGui.

local frame = game.StarterGui.ScreenGui.Frame

for i = 1, 9, .1 do
    frame.Transparency = i
    wait()
end

And to do it for multiple frames, I would personally variables as I did with local frame, for example:

frame = game.StarterGui.ScreenGui.Frame
frame2 = game.StarterGui.ScreenGui.Frame2
frame3 = game.StarterGui.ScreenGui.Frame3

for i = 1, 9, .1 do
    frame.Transparency = i
    frame2.Transparency = i
    frame3.Transparency = i
    wait()
end

For more information on loops

0
I knew were frame was from, I was just lazy to put a variable so I just showed an example. This helped thanks! IntellectualBeing 430 — 9y
Ad
Log in to vote
1
Answered by
Aethex 256 Moderation Voter
9 years ago

You would use a for loop to make this more efficient.

for i = 1, 10 do

    Frame.Transparency = i/10;

    wait(0.1);

end

Answer this question