While Loop inside thread

self.thread = task.spawn(function()
	while true do
		local success, previousActivity = self:SetActivity()
		if success then
			script.Parent.Parent.httpClient:SetAttribute("previous", previousActivity)

If I use task.cancel(self.thread) does it stop the while loop? Thanks!

Yeah so in this case task.cancel(self.thread) will stop the execution of the coroutine represented by self.thread.

For this simple task I just need task spawn and task cancel, I don’t need to use coroutine “way” right?

Right. Here’s the thing though, in this case, you’re using task.spawn and task.cancel to manage the execution of a function. You don’t need to manually handle coroutines as the task.spawn function already handles coroutine creations. So, you can use task.spawn to start the function and task.cancel to stop it.

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