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

While true do help?

So i know while true does,Heres an example

while true do
wait()
print("Hi Mom")
end

But what if i want it to repeat itself? Like re-start. I know theres the "break",Is there something similiar but "repeat"?

1 comment

3

The code you have should repeat printing 'Hi mom'. Elaborate on what you're asking please.

1 answer

✓ Accepted answer

edit: Was wrong. Edited the answer to fit better. It seems that I was incorrect, many apologies.If you read the comments, wait() holds the wait for the smallest time interval. This should repeat it correctly. As for breaking a while true do loop, simply type break whenever you wish inside of it, and it will stop it. The most practical use for break is when you are doing a conditional branch where you have different If statements and different loops for each one of them. For restarting a loop, the break command will come into use. What you would do is use If statements and breaks. (There are many alternatives, but this would be the simplest way, I believe.)

Here is an example.

while true do
wait()
print 'Hi mom!'
canchange = false
--here you can either have an outside force change the variable, or already have it set to true and have waits to time it.
	if canchange = true then
	break
		while true do
		print 'Hi dad!'
	end
end

4 comments

0

It will repeat, and wait() is perfectly valid - wait() will suspend for the smallest interval possible which, in most cases, is 1/30th of a second.

0

wait() waits for 1/30th of a second, duckwit is right... why is this the chosen answer?

0

Perhaps due to the way I answered his question about Break.

0

I edited my answer to be correct... Many apologies. e_e

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