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

How do i return loop few times?

Hello, I want to know how to make few times loop, cause i want to make it easier to write, instead of:

print("Print")
print("Print")
print("Print")
print("Print")
print("Print")
print("Print")

Can i get some help to use few times loop instead of few times of the same thing?

1 answer

✓ Accepted answer

You can use a for loop, for example:

local function WriteLine(text)
	print(text)
end

-- 0 is the starting point, 5 is where it will end, and 1 is the number it will be incrementing by.
for i = 0,5,1 do 
	WriteLine(i..". This is the text that will be printed.")
	wait(1)
end

Another example:

local function WriteLine(Start, End, Increment, Time, Text)
	
	for i = Start, End, Increment do
		print(Text)
		wait(Time)
	end
end

WriteLine(0, 5, 1, 1, 'Text that will be printed.')

A for loop is useful for having a loop run for the number of times you set it to. In this for loop I set it to start at 0 and end at 5 by incrementing by 1 every 1 second. You can see more information about for loops here.

1 comment

0

Thanks! It worked.

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