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

Help with for loop on transparency?

I'm a new scripter that is trying to make a brick appear dramatically by a bit of CFraming and so.

But when I try and make it so then it starts off invisible and turns visible, I just don't know how I can do it.

I know I will need the for loop, but that is all I can think of.. Any help will be appreciated.

1 answer

✓ Accepted answer

First we need to decide how many "cycles" it will take for it to go invisible.

cycle = 6 -- 6 loops for it to go 100% invisible

We will also need a variable for the brick itself

brick = game.Workspace["Some brick name"]

Now we need to for statement

num = 1 / cycle

for i = 1, cycle do
	brick.Transparency = brick.Transparency - num -- Subtract = Get invisible / Add = Get visible
end

Explained:

Line 1: We need to figure out what number, when added/subtracted 6 times, will get us to 1. We can do that by dividing 1 by the cycle (6)

Line 3: Here, we need to let the script know it needs to be done 6 times total

Line 4: Now it is time to to change the transparency

Now we put it all together!

cycle = 6 -- 6 loops for it to go 100% invisible
brick = game.Workspace["Some brick name"]
num = 1 / cycle

for i = 1, cycle do
	brick.Transparency = brick.Transparency - num -- Subtract = Get invisible / Add = Get visible
end

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