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

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

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

✓ Accepted answer

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.

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

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