I'm going to simplify my script here:
endroutine = false func = coroutine.wrap(function() while true do wait() --do some stuff that has to happen with other stuff unless stuff is done if endroutine then return end end end) func2 = coroutine.wrap(function() while true do wait() --do other stuff that has to happen with other other stuff end end) function dostuff() --do stuff endroutine = true --do more stuff endroutine = false func() end func() func2() wait(10) dostuff()
My issue is that when func() is called in dostuff(), I get an error along the lines of: "Unable to resume dead coroutine."
I tried the following:
endroutine = false function func() while true do wait() --do some stuff that has to happen with other stuff unless stuff is done if endroutine then return end end end func2 = coroutine.wrap(function() while true do wait() --do other stuff that has to happen with other other stuff end end) function dostuff() --do stuff endroutine = true --do more stuff endroutine = false coroutine.wrap(func()) end coroutine.wrap(func()) func2() wait(10) dostuff()
For some reason, the above code makes it so func2() never even runs in the first place, which is a problem since I need func() and func2() to run at the same time.
Simply put: Is there a way I can get both func() and func2() to run at the same time, and after func() has ended via "return end", be able to start it again from it's call in dostuff()?
Preferably without a lot of new lines of code; I like to try and keep my code as compact as possible.
It should be noted that in the actual script, dostuff() is called via a MouseClick event, not directly in the script.
You can't call functions that were not scripted prior to them being called. When I say this, I mean the server reads the code from top to bottom. When it comes across func() in the beginning, the server has no idea what you're talking about since it hasn't gotten to that code yet. That's why I suggest always having things CALLED at the bottom of a script, and all functions to run things at the top of a script so there's no chance for anything to error in that fashion! Hope this helped.