So I am on a quest to make a functional thread manager. It can re-use threads that are cached in a table that can be pulled at any time. So I'm testing it with some lighting and boolean's and the module that controls the lighting requires a boolean to turn on/off the lights. But I keep running into an error. The thread does run but doesn't seem to operate and errors.
Any ideas?
local _ModuleEffects = script.Parent:WaitForChild("Effects")
local _COMMANDS = {}
local _THREADS = {}
-- Threading --
local AddNewThread = function(EffectName, ...)
local NewThread = coroutine.create(...)
_THREADS[EffectName] = NewThread
return NewThread
end
local FindOldThread = function(EffectName, ...)
if _THREADS[EffectName] ~= nil then
return _THREADS[EffectName]
else
return false
end
end
local RemoveThread = function(EffectName, ...)
local Thread = FindOldThread(EffectName)
if Thread ~= false then
_THREADS[EffectName] = nil
end
return _THREADS[EffectName]
end
local ThreadStatus = function(EffectName, ...)
local Thread = FindOldThread(EffectName)
if Thread ~= false then
return(EffectName.." status: "..tostring(coroutine.status(Thread)))
end
end
local RunThread = function(EffectName, ...)
local Thread = FindOldThread(EffectName)
if Thread ~= false then
coroutine.resume(Thread)()(...)
print("Running thread "..EffectName)
else
local Module = _ModuleEffects:FindFirstChild(EffectName,true)
if Module then
AddNewThread(EffectName, require(Module))
print("Created new thread for "..EffectName)
end
end
end
-- Returning functions to operate --
return RunThread

1 comment
Saying exactly what the error is and showing us what you're using to test this code would be helpful - based on your current description (without analyzing the code), I can only conclude that "an error" occurred.