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

How would a loop work?

What kind of loop would you use if you wanted the loop to keep on going while the rest of the script kept going also because I know some loops you can't do that but I'm not sure which loop can go on while the other parts of the script also go on.

1 answer

✓ Accepted answer

I will not make a script for you, this seems like a request. But I will help by giving you some loops that I use:

--The "for" loop:
for i = 1, 10 do --Repeats everything before end 10 times
	print(i) --prints how many times it has repeated
end

--The repeat, until loop:

repeat
	if value == true then --To make sure you do not get stuck in a loop
		break --Break the loop if value is true
	end
	wait()
until value == true

--the "function" loop as I call it:

function RepeatMe()
	--code
	RepeatMe() --makes RepeatMe loop
	--If you do not want it to be infinite then add an if statement or something like
	--[[
	if repeat == true then
		RepeatMe()
	end
	]]--
end

RepeatMe() --Starts the loop

--The while loop:

while true do
	print("OMG HAX")
	wait() --ADD A WAIT! Otherwise the script will overload the game!
end

--or you can do

while value == true do
	print("OMG HAX")
	if value == false then
		break --Break the loop in case it gets stuck
	end
	wait() --ADD A WAIT! Otherwise the script will overload the game!
end

--That's about all I can think of so far...

If you are making a minigame game or something that has rounds then I recommend the function loop.

2 comments

0

That's not what I meant what I meant is a loop continues and continues and continues while the rest of the script continues doing whatever

0

But thanks I got the RepeatMe loop to do that

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