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

Function That Starts Loop From Beginning Upon Requirement Being Met ?

Asked by 5 years ago

Is there a feature in Roblox Lua where if a a certain requirement is met, the loop starts again from the beginning?

0
I dont know if this applies to your situation, but if you're using any type of Value (Bool, Int, Number, Object) you can do Value.Changed event for a function. "Value.Changed:connect(function()" ininja966 20 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Well, there are a couple things you can do.

For 1, you can put a conditional statement (If Statement) and then a loop under it so it will run if the requirement is met.

An example is:

local a = true

if a = true then
    while true do
        wait()
        print('a is true')
    end
end

Another thing you can do is combine the loop with the statement. This is commonly used in infinite loops. Here is an example:

local a = true

while a do -- this is equal to while true do since a is true now u can put other statements such as 1 + 1 = 2 and so on
    wait()
    print('dis works')
end

If you wish to loop for a specific amount of times every second:

local a = true

if a then
    for i = 0, 10 do -- loops 10 times 
        wait()
        print('Looped'..i)
    end
end

Hopefully, this helped and was what you were looking for.

Best of luck developer!

Ad

Answer this question