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

Trying to change the transparency of a brick every 120 seconds?

Asked by
Ulysies 50
10 years ago

I have the part were the transparency changes but I haven't scripted in a while and so I don't know what to do next..

01local function Close(Blib1)
02    Blib1.Transparency = .2
03    wait(2)
04    Blib1.Transparency = .6
05    wait(2)
06    Blib1.Transparency = .8
07    wait(2)
08    Blib1.Transparency = 1
09 
10end
11 
12 
13local function Open(Blib1)
14    Blib1.Transparency = .8
15    wait(2)
View all 22 lines...

2 answers

Log in to vote
1
Answered by 10 years ago

There are many ways to achieve this, but I will highlight only the most efficient way.


Firstly, you could implement a while loop with wait(20) to improve the efficiency of the code.

1while wait(120) do
2end;

Next, we can use a boolean to store the status of the door.

1local open = true;
2while wait(120) do
3open = not(open);
4end;

Now, we will use the and / or operators to determine which function to run.

1local open = true;
2while wait(120) do
3open = not(open);
4local run = (open) and Open or Close;
5run(workspace.Part); -- chance to what Blib1 should be.
6end;

NOTE: This was written for use with your current functions.

Ad
Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

Use a while loop to continuously loop it:

1while true do
2wait(120)
3end

While Loop Composition:

1while (argument) do
2wait(WaitTime)
3end

Perhaps use a for loop to script more efficiently in place of your functions :

1for i = 1, 5 do
2    script.Parent.Transparency = script.Parent.Transparency + .2
3    wait(2)
4end
5wait(2)
6for i = 1, 5 do
7    script.Parent.Transparency = script.Parent.Transparency - .2
8    wait(2)
9end

For Loop Composition:

1for (variable) = (start number), (end number), (increment (default = 1)) do
2    wait(WaitTime)
3end

Answer this question