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

Is there a way to make this code possibly shorter?

	for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
	end
	
	wait(1)
	
		for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency + .1
		end
		
		wait(1)
		
		for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
	end

wait(1)

		for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency +.1
	end

wait(1)

		for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
	end

1 comment

0

use the i parameter stop wasting your computer's resources wasting calculations on the i parameter already

1 answer

✓ Accepted answer

Sure! Just use a while loop. This will keep it going forever,

while true do
	for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
	end
	wait(1)
	for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency + .1
	end
end

To keep it looping a certain amount of times, just create a value and make it increase after each loop.

local LoopBreak = 0
while true do
	if LoopBreak == 5 then --Once the LoopBreak reaches 5, it will break the loop.
		break
	end
	for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
	end
	wait(1)
	for i = 1, 10 do
		wait(0.01)
		pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency + .1
	end
	LoopBreak = LoopBreak + 1 --Increases the value by one everytime it loops.
end

4 comments

0

Thanks, this is perfect. But how would i make it loop for about 5 times?

0

I'll edit the question for ya.

0

K thanks

0

Alright Thanks For Helping :)

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