How can I wait for a thread to complete?

I want to make a thread like below:

self.Thread = task.spawn(function()
	self:Event()
end)

Is there any way to make the script wait until the thread is complete? (aside from running the function without the task.spawn() method)

You wanna create a coroutine instead. There you can detect whether it’s over or not

local t = coroutine.create(function()
   self:Event()
end)
coroutine.resume(t)
repeat wait() until coroutine.status(t) == “dead”
1 Like

fyi: coroutines = threads, the words are interchangeable. task.spawn will return a thread as well.

self.Thread = task.spawn(function() end)

repeat task.wait() until coroutine.status(self.Thread) == "dead"
2 Likes

That is quite cool. But i’d prefer the set

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.