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
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.