Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does anyone know how to permanently delete a thread?

Asked by
abrobot 44
4 years ago

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

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

01local stop --Create stop variable with nil value
02coroutine.resume(coroutine.create(function() --Create an anonymous thread and resume it.
03    while true do
04        game:GetService("RunService").Heartbeat:Wait()
05        if stop then break end --If stop variable is true then stop the loop!
06        print("I will forever run, nothing will stop me!")
07    end
08end))
09 
10wait(5)
11stop = true --Let's stop the unnecessary loop now!
Ad
Log in to vote
0
Answered by 4 years ago

You can do return for functions or break for loops.

Answer this question