I need to stop a thread. I don't really have anything more to add other than that.
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.
01 | local stop --Create stop variable with nil value |
02 | coroutine.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 |
08 | end )) |
09 |
10 | wait( 5 ) |
11 | stop = true --Let's stop the unnecessary loop now! |