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

Is it possible to iterate a loop for x seconds?

Asked by
Kap_K 0
6 years ago

Is it possible for a while loop to run an x amount of time. Filling in the wait function as the parameter was useless... Is there any way to make this loop run for x amount of seconds in the best way possible to save memory and reduce complexity? And does Roblox have any more parameters on a While loop besides the condition?

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

There is repeat, if loops, while loops, for loops, Right now we are going to work with repeat loops, while loops and for loops.

For Loops:

local timer = 5 -- till how many seconds...
for i=1,timer,1 wait(1) do
    print(i.."/"..timer) -- This may error since I don't normally concatenate prints..
end

^ a way of a countdown every second, just add wait there.

While Loops:

local t = 1
while wait(1) do
    t = t + 1
    if t >= 5 then
        break
        print("Reached end.")
    end
end

I recommend you don't use this ^

Repeat Loops:

local a = 1
repeat wait(1)
    a = a + 1
    print("Timer is counting down.")
until a >= 5

Roblox doesn't have parameters on while loops, instead conditions which if you put a function, you can input parameters into.

The best way to save memory is the for loop since it is extremely short and easy to use.

I hope this helped, Thanks.

And any way to change the amount of seconds or add a wait time, you would simply put

wait(x) --  x being your number. This isn't in milliseconds but instead seconds.
0
NEVER do while wait() do DeceptiveCaster 3761 — 6y
0
it's bad for your game DeceptiveCaster 3761 — 6y
Ad

Answer this question