[Outdated]Custom Wait - A way to cancel waits

Like many probably know. You cant cancel a task.wait() function. When you call it you need to wait until it has completed running.

Well i introduce to you :drum: :drum:

CUSTOM WAIT

β†’ Module https://create.roblox.com/marketplace/asset/13086318713/Custom-Wait

Custom wait is like your oridinary task.wait(). The only minor difference is that you can actually cancel it.

Api:

CustomWait.new(Seconds) --> Returns a new Wait object.

CustomWait:Enable() --> Starts counting(Will yield). Cant be called again if its in use.

CustomWait:Cancel() --> Cancels the wait.

CustomWait:Destroy() --> Locks it from being reusable.

Example:

local CustomWait = require(game.ReplicatedStorage.Modules.Utilities["Custom Wait"])



local Wait = CustomWait.new(5)


task.delay(2,function()
	Wait:Cancel()
end)


Wait:Enable()
print("Reached end.")

If youve got any feedback make sure to post em in the replies. All feedback is very appreciated positive/negative.

7 Likes

I loved your presentation.
It is certainly easier to use and understand than the coroutines. Good job

local thread = coroutine.running()
task.delay(2,function()
    coroutine.resume(thread)
end)
task.wait(5)
print("Reached end.")
1 Like

Really cool idea, good implimentation. Good work :+1:

It would be nice if there was an interval property, so it didn’t wait every heartbeat. For example, you can have interval .5 and it will wait half a second before checking if it’s disabled.