Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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?

0
put "break" under wait and see what happens Sapppower 17 — 5y
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. SoftlockedUnderZero 668 — 5y
0
This loop will continue running until true is no longer true. Put "break" so it exits the loop. SaltyIceberg 81 — 5y
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. greatneil80 2647 — 5y
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. greatneil80 2647 — 5y

2 answers

Log in to vote
-1
Answered by 5 years ago

fix

local Time = 0
local Delay = 10
spawn(function()
while wait(Time) do
print("In")
wait(Delay)
end
end)
print("Out")
0
Thanks dude it worked! Oskar2266001 3 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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!")

Answer this question