How do I Wait after the loop

How do i wait after the loop? For example like:

local rept = false

rept = true

while task.wait() and rept == true do
print(“repeating”)
end

wait(1)

rept = false

print(“break loop”)

This is just an example, but this code while running is not what i expected to be. So what i want to do is when it loops. It keeps looping until after the wait(1) . I have another solution that use:

for i = 1, 60 do – 1 second = 60 times of task.wait()
– which is 0.015 seconds
print(“repeating”)
task.wait()

end

print(“break loop”)

If there are more solutions about using loop please help me.

What do you mean wait after the loop? You can use

while true do
wait()
--code
end

or if you are talking about waiting after the break then

while true do
wait()
if condition == condition then
break
end
end

wait()

EDIT: added wait() to while true do

1 Like

I want to do like loops while waiting for 1 second. But i’ll try the script you wrote to me later.

A bit confusing at first, but I think I got what you mean.

So you can actually create a new thread with either task.spawn or with the coroutine library like so (I’ll be using coroutine.wrap):

local coroutineSpawned = false
local dropLoop = false
for i = 1, 60 do -- 1 second = 60 times of task.wait()
if dropLoop then break end
-- which is 0.015 seconds
if not coroutineSpawned then
coroutine.wrap(function()
    coroutineSpawned = true
    task.wait(1)
    dropLoop = true
    end)()
end
print("repeating")
task.wait()
end

If you need an explanation, I’d be happy to explain it to you. Maybe not on my alt (this account that I’m on) though

1 Like

I’ll try later. Thank you so much.

1 Like

Please type 3 backticks before and after your scripts when you put them here so they format properly.
I think I understand what you’re asking, try this:

local timer = 0
local rept = true 

repeat  -- this will run the following script until the conditions met in the until line below are met
    timer += 1  -- adds one to the timer
    print(timer)
    print(rept)
    -- you'll have to script how to change rept to false somewhere else 
    task.wait()  
until rept == false or (not sure, you may have to add another *until* here) timer == 60 

print("loop broken because rept changed to false, or timer reached 60")
1 Like
local isLooping = true

task.delay(1, function()
    isLooping = false
end)

while isLooping do
     task.wait()
     ...
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.