self.thread = task.spawn(function()
while true do
local success, previousActivity = self:SetActivity()
if success then
script.Parent.Parent.httpClient:SetAttribute("previous", previousActivity)
end
task.wait(1)
end
end)
If I use task.cancel(self.thread) does it stop the while loop? Thanks!
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.