The main question I want to ask about how to use task.spawn()
, task.delay()
, do I need to make a connection and disconnect, and when should I use disconnect, which will auto removed by roblox default?
task.spawn/delay will get garbage collected automatically if the passed function/thread doesn’t run forever
--no need to disconnect because the thread will get garbage collected automatically after print("cool")
task.spawn(function()
print("cool")
end)
-- the function runs forever which means that you will need to disconnect/close it manually
task.spawn(function()
while true do
print("cool")
task.wait()
end
end)
3 Likes