What do you want to achieve?
I want to successfully yield a coroutine
with a wait()
, and still run the coroutine
, or at least make a new coroutine.
What is the issue?
The running coroutine
duplicates because of Roblox’s thread scheduler.
What solutions have you tried so far?
I have tried manipulating Lua’s garbage collecter, forcefully executing an error in the coroutine, and yielding the coroutine.
I’m sort of confused with what you’re trying to do.
There’s coroutine.yield()
which will yield the current coroutine until coroutine.resume(thread)
is called.
not sure if that’s what you’d be looking for.
huh? Can you elaborate on what exactly you wanna achieve? As far as I can understand, you want to yield a thread and run a function?
So you essentially want to cancel a wait()
call that’s still yielding the current thread?
So, calling a wait
in a coroutine
triggers Roblox’s thread scheduler, and that schedules the coroutine
in the amount of seconds inputted in the wait
function. It still runs even if you yield the coroutine
. I want to cancel/yield that coroutine
.
You can’t cancel a scheduled coroutine.
Couroutine.yield
as simple as that…
Alright. Is there any alternatives or workarounds? Should I even be using coroutine
s?
It depends what you’re trying to do, because you have not told us.
I am trying to convert a KeyframeSequence
used to animate a custom rig into a ModuleScript
in a plugin. The ModuleScript
that is generated is where the code is located. The ModuleScript
is executed by a ServerScript.
And what exactly is the problem?
The animation runs twice because the coroutine
is scheduled even after the “Stop” function is called. The “Stop” function stops the coroutine
executing the animation.
The problem is probably with the code, because coroutines are not duplicated when yielded. You can always pass an information to the coroutine when resuming it that it should stop instead of continuing the execution of the thread.
Sorry. The wait
in the coroutine
is whats causing the thread to duplicate.
Can you show some code, because I have never heard that wait would duplicate a coroutine.