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

How can I execute more code after a loop?

Asked by 6 years ago

how can i run a while or repeat loop while being able to execute more code after that example:

print'called first'

while true do
wait(5)
print'5 second check'
end

print'called last' -- This does not work, I want it to though

i wanna be able to do stuff after the loop, thanks :)

2 answers

Log in to vote
0
Answered by 6 years ago

simple.

print('called first')

spawn(function()
    while true do
        wait(5)
        print('5 second check')
    end
end)

print('called last')
Ad
Log in to vote
0
Answered by 6 years ago

I know this is answered already but I'll say another way.

print("called first")

local a = coroutine.wrap(function()
    while wait(5) do -- This is completely valid and saves you a line.
        print("5 second check")
    end
end)

a() -- This is easily forgotten, make sure you do it or else it won't run.

print("called last")

Output:

called first

called last

5 second check

0
ur making all hard bro Lolamtic 63 — 6y

Answer this question