Created
March 1, 2023 01:00
-
-
Save MagmaBurnsV/3a1c018cbf016cf3096d82cb006a9f0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--!strict | |
-- // Helper Functions | |
local function Debounce(self: Cooldown): () | |
self.Status = false | |
end | |
-- // Cooldown Class | |
local Cooldown = {} | |
Cooldown.__index = Cooldown | |
type self = { | |
Status: boolean, | |
Time: number, | |
Running: thread? | |
} | |
export type Cooldown = typeof(setmetatable({} :: self, Cooldown)) | |
function Cooldown.new(Time: number): Cooldown | |
local self = setmetatable({ | |
Status = false, | |
Time = Time, | |
Running = nil | |
}, Cooldown) | |
return self | |
end | |
function Cooldown.CanPass(self: Cooldown): () | |
return not self.Status | |
end | |
function Cooldown.Start(self: Cooldown): () | |
if self.Status then | |
warn("Cooldown started while still Active") | |
end | |
self.Status = true | |
self.Running = task.delay(self.Time, Debounce, self) | |
end | |
function Cooldown.Cancel(self: Cooldown): () | |
if not self.Status then | |
warn("Cooldown cancelled while not Active.") | |
end | |
if self.Running then | |
task.cancel(self.Running) | |
end | |
self.Status = false | |
end | |
return Cooldown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment