Create a table of coroutines with module script functions

I would like to create a table of coroutines using functions from a module so that I can close/yield anytime I want:

local gameUI = require(script.GameUI)
module.SaveCoroutine = function(functionName,...)
	if module.Coroutines[functionName] then
		coroutine.close(module.Coroutines[functionName])
	end
	module.Coroutines[functionName] = gameUI[functionName]
	module.Coroutines[functionName](...)
end

module.EndGame = function()
	print(module.Coroutines)
	for _, fnction in pairs(module.Coroutines) do
		coroutine.close(fnction)
	end
end

An example of a function in that specific module

module.GameStart = coroutine.wrap(function(...)

If I print the module, all values come out as “function” in string format.

Changing the coroutine.wrap into a coroutine.create solved the problem

module.Coroutines[functionName] = coroutine.create(gameUI[functionName])
coroutine.resume(module.Coroutines[functionName],...)

in the desired module:
module.GameStart = function(...)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.