How do I get the current state of a task?

How do I know whether a task has been cancelled yet or not? Let’s say I have a variable assigned to task.spawn() and I want to know whether that task is running currently, has completed, or been cancelled. What can I use to figure this out? I know it’s possible with coroutines.

local TestFunction = function()
print("Called!")
end

local Thread = task.spawn(TestFunction)
print("Cancelling..")
if Thread then --//What can I do to get the current status of "thread"? Whether task.cancel() has been called or not.
	task.cancel(Thread) 
	print("Cancelled.")
end
2 Likes

You can use coroutine.status()

5 Likes

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