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
3 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 3 years ago
Edited 3 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.

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!
Ad
Log in to vote
0
Answered by 3 years ago

You can do return for functions or break for loops.

Answer this question