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?
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.