Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Does anyone know how to permanently delete a thread?

I need to stop a thread. I don't really have anything more to add other than that.

2 answers

✓ Accepted answer

A thread is a method that allows you to run multiple lines of code at once when a particular code yields. You don't cancel a thread. If you're using a loop inside of a thread, you can use break to stop the loop. As @INot_here said.

local stop --Create stop variable with nil value
coroutine.resume(coroutine.create(function() --Create an anonymous thread and resume it.
	while true do
		game:GetService("RunService").Heartbeat:Wait()
		if stop then break end --If stop variable is true then stop the loop!
		print("I will forever run, nothing will stop me!")
	end
end))

wait(5)
stop = true --Let's stop the unnecessary loop now!

You can do return for functions or break for loops.

This discussion is preserved as it was. New answers, comments, and votes are closed.