Threads aren't cancelled when the local script is disabled or destroyed

(note: this bug report specifically used task.spaw(), but the issue is most likely present in coroutines and spawn)

Client scripts will not cancel threads when disabled/deleted.

for example, this code prints (i tested it):

task.delay(5, function()
	print("hi from thread that should not exist")
end)

script:Destroy()

this is really confusing and annoying.

The only way you can avoid this is by cancelling the thread before deleting/disabling the script. This is pretty impractical though.

Issue area: task scheduler
Issue type: task cancelling
Frequency: constant
Impact: high

2 Likes

I don’t think this is a bug, but rather intended behavior.

3 Likes

it doesn’t really make sense though

1 Like

Hi @bloodbonniekingnoob1,
I am either misunderstanding your bug description, or having problems getting the issue to repro using your script in Studio.

I copy/pasted your script into a new script (running on Client) and ran the experience. When I run the experience I don’t see any output (i.e the print statement doesn’t execute). Is there anything else I may need to do to reproduce the issue?

If you still see the issue, could you send me a place file that demonstrates the issue? Then I can make sure I am running the exact same scenario as you.

Thanks!

2 Likes

Hello. I have realized this is NOT a bug, but the script was somehow deleting itself as soon as it was created, which resulted in the script not being deleted. I am sorry for wasting everybody’s time, I thought this might have been the case due to a past bug in a game I had where a remote would still be fired on the client even though the script was disabled.

1 Like

Thanks for posting this update and letting us know it wasn’t a problem.

1 Like

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