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

How to use this coroutine?

Asked by
wjs3456 90
10 years ago

I have this script here as practice with coroutines, but it doesn't seem to work. Am I right that it has something to do with the if statement?

local down = coroutine.wrap(function()
    time_left = script.countdown.Value--value is 900. 
        while true do
        time_left = time_left - 1
        wait(1) 
        print(time_left)    
    end 
end)

down()

local stop = coroutine.wrap(function()
    if script.countdown.Value == 890 then--890 for testing
        script.countdown.Value = 900
end
end)
stop()
0
Why are you using two coroutines for this? You shouldn't need one at all BlueTaslem 18071 — 10y
0
Wouldn't it just keep going forever? And I want it to be two different scripts so I can apply it to what I'm working on wjs3456 90 — 10y
0
coroutine.resume(down) and you'd need a while loop in the stop also, HOWEVER, I recommend a .Changed event to be called on script.countdown Lacryma 548 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

You don't need courtliness... Unless you want to run a function at the same time, however this is a simple script that is better... In my opinion hope it helped!

local time = 900
function countdown()
for i = 1,900 do
wait(1)
time = time-1
print(time)
end
--What to do after that countdown is over
end
countdown()
Ad

Answer this question