https://www.roblox.com/library/9881891628/PausedThread
A simple module to pause and resume a delay, with similar syntax to delay() or task.delay().
Example:
local Thread = PausedThread.new(
-- Delay time
5,
-- Callback function
function(onePlusOne)
print('1 + 1 =', onePlusOne);
end,
-- Whether or not to start the thread paused (optional)
false,
-- Any arguments passed here will be passed to the callback
1+1
);
Thread.onPauseChanged:Connect(function(isPaused)
print('This thread is now:', isPaused and 'Paused' or 'Resumed');
end);
task.wait(1);
Thread:Pause(); -- Delay will pause
task.wait(5);
Thread:Resume(); -- Delay will resume
--Thread:Cancel(); -- Delay will destroy and run callback
--OR
--Thread:Destroy() -- Delay will destroy and NOT callback
Source code available in the module!
Credits
- @stravant for GoodSignal