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..

    local function Close(Blib1)
        Blib1.Transparency = .2
        wait(2)
        Blib1.Transparency = .6
        wait(2)
        Blib1.Transparency = .8
        wait(2)
        Blib1.Transparency = 1

    end


    local function Open(Blib1)
        Blib1.Transparency = .8
        wait(2)
        Blib1.Transparency = .6
        wait(2)
        Blib1.Transparency = .2
        wait(2)
        Blib1.Transparency = .0

    end

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.

while wait(120) do
end;

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

local open = true;
while wait(120) do
open = not(open);
end;

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

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

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:

while true do
wait(120)
end

While Loop Composition:

while (argument) do
wait(WaitTime)
end

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

for i = 1, 5 do
    script.Parent.Transparency = script.Parent.Transparency + .2
    wait(2)
end
wait(2)
for i = 1, 5 do
    script.Parent.Transparency = script.Parent.Transparency - .2
    wait(2)
end

For Loop Composition:

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

Answer this question