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

Help with for loop on transparency?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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
Ad

Answer this question