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

My coroutine for dialogue options won't work?

So I have some dialogue and I want two options: one you can press, and one that has a timer. I need to fit both in only one script, so I tried to use a coroutine to make the timer go while you're able to press the first button, but it won't work at all (proven with prints). does anyone know why? here is my code:

	coroutine.wrap(function()
	print("coroutine")
		for i=5, 1, -1 do
			wait(1)
			print(i)
			rightoption.Text = i
		end
	end)

Just for clarification,, the console outputs nothing.

2 answers

✓ Accepted answer

Hello!

First of all, the coroutine.wrap() works with the parameter to be a function.

local value = 0

local function Test()
	print("coroutine")
	for i=5, 1, -1 do
		wait(1)
		print(i)
		value = i
	end
end

coroutine.wrap(Test)()

Here is the fixed code, you have to remove the value variable (I used it for testing). Also it isn't looping, if you wanted to do that.

1 comment

0

It worked! Thank you!

Adding on to SuperPuiu's explanation, you can wrap undeclared functions

coroutine.wrap(function()
	print("Coroutine")
end)()

To pass parameters, do:

coroutine.wrap(function(msg)
	print(msg)
end)("Coroutine")

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