So I have this script:
function countdown() time_left = 900 while true do time_left = time_left - 1 wait(1) end end
It works but the problem is is that I want it let the other functions after it to also go. Is there any way to place the while true do somewhere else or is there another loop type
Thanks
Ya, I had this same kind of problem, try using Coroutine
's, this type of Coroutine
I'm about to show you, it can do multiple codes at once;
coroutine.resume(coroutine.create(function() while true do wait(5) print("I'm in a coroutine!") end end)) coroutine.resume(coroutine.create(function() while true do wait(5) print("I'm in a coroutine too!") end end)) while true do wait(5) print("I'm not!") end
As you'll see, every 5 seconds, the three loops will print I'm in a coroutine!
, I'm in a coroutine too!
, I'm not!
in the Output.
The coroutine.resume(coroutine.create(function() end))
allows you to do multiple loops/codes at once.
Head to this link for more information about Coroutine
's, http://wiki.roblox.com/index.php?title=Coroutines
.
Hope this helped!
Using a while true do blocks all functions after it. I suggest using a more simple countdown like a loop for example.
local time = 900 function countdown() for i = 1,900 do wait(1) time = time-1 end
Is there any way to make it so you could do something like this?
if time_left==0 then time_left = 900 end