script:Destroy() ends other threads but not the main one

coroutine.resume(coroutine.create(function()
	wait(1)
	print("hello")
end))
print("Destroying")
script:Destroy()
print("Destroyed")

This outputs

Destroying
Destroyed

iirc it isn’t supposed to keep running to be able to print “Destroyed” after it’s been destroyed. My other concern is that while the thread keeps running, the coroutine dies and never prints “hello”

Is this supposed to work this way?

1 Like

I thought scripts stopped and re-started if they changed parents, e.g.

wait()
if script.Parent==workspace then script.Parent=game.ServerScriptService end
if script.Parent==game.ServerScriptService then script.Parent=workspace end
print("parent",script.Parent)

should never print and should repeatedly change parents, but it does print now and does not repeatedly change parents.

I guess that all threads by te script in the thread scheduler gets removed, so they never resume.
The current thread is already running, so it keeps running.
(they probably could stop it on :Destroy(), but it might be a tad annoying and unnecessary)

If you do spawn() after :Destroy(), the spawn should work again.

Lots of SB scripts use(d) this to lock the script, so it can’t be reparented 'n stopped 'n stuff.

1 Like