I have a while loop in my task.spawn thread and the thread is accessed through a table. Now outside the thread, I have a function to cancel the thread, and before doing so, checks if it’s in the table. If it’s in the table, then it proceeds to cancel it, which sometimes results in an error. For now though, I put it an a pcall, but all I’m wondering is how this error is created.
2/19/2023
I didn’t actually use coroutines to fix my problem, I just stopped using task.spawn and task.cancel. Task.spawn is okay to use, but not with task.cancel; task.cancel is super buggy and I don’t even know how to reproduce the bugs. So, what I used was a regular while loop connected to a bool value and whenever the bool value went to false, the while loop would break.
Coroutines might’ve fixed the problem too, but I didn’t want to research coroutines at the time because my anti-cheat was quite broken.