Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use this coroutine?

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()

3 comments

0

Why are you using two coroutines for this? You shouldn't need one at all

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

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

1 answer

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.