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

What's a better way of doing this?

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

✓ Accepted answer

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

1 comment

0

I knew were frame was from, I was just lazy to put a variable so I just showed an example. This helped thanks!

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

for i = 1, 10 do

	Frame.Transparency = i/10;

	wait(0.1);

end

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