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

[SOLVED] Anything under While loop doesn't run until you break it? Any fix?

so iv been trying to make my first game the idea is you get Teleported to a map you get a sword and the last person to die wins and gets points iv been trying to fix this problem for days but them i tried to run a code under a while loop and it didn't work? so then i made a short script to test if anything under will run and it didn't Any Help? Here's the simple script:

while wait() do
    print("In side loop print")
    wait(10)
end
print("Outside loop print")

As you see it doesn't print OutSide loop print Any Help?

5 comments

0

put "break" under wait and see what happens

0

Reminder that while loops will always run on themselves until broken. Ignoring the code outside. Breaking the loop allows the script to continue executing code.

0

This loop will continue running until true is no longer true. Put "break" so it exits the loop.

0

use spawn(function(), it creates a seperate thread of what you want. which allows you to run a loop and print outside the loop.

0

use spawn(function(), it creates a seperate thread of what you want. which allows you to run a loop and print outside the loop.

2 answers

✓ Accepted answer

fix

local Time = 0
local Delay = 10
spawn(function()
while wait(Time) do
print("In")
wait(Delay)
end
end)
print("Out")

1 comment

0

Thanks dude it worked!

You have to figure out if you want your loop to run forever, or if you want it to run until some condition is met. One common method is to use a "flag" to tell the loop to continue running:

local keepGoing = true   -- Flag
while (keepGoing) do
    -- Stuff
    if (stuffDone) do
	    keepGoing = false
	end
end
print("Loop over!")

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