Skip to content

Instantly share code, notes, and snippets.

@MagmaBurnsV
Created March 1, 2023 01:00
Show Gist options
  • Save MagmaBurnsV/3a1c018cbf016cf3096d82cb006a9f0f to your computer and use it in GitHub Desktop.
Save MagmaBurnsV/3a1c018cbf016cf3096d82cb006a9f0f to your computer and use it in GitHub Desktop.
--!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