Sometimes task.cancel errors

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.

1 Like

I suggest instead of using task.cancel and task.spawn, use 2 things:

  1. coroutine.wrap(function(...) end)(...)
  2. Send a parameter for a table index through
  3. Check inside the coroutine.wrap, if the value is true if it is you break it off.

It’s unreliable to use task.cancel and task.spawn, you’ll need to find a workout like what I wrote above.

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