Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local module = {}
- local Storage = {}
- function module.new(Player: Player, Name: string, Duration: number)
- Storage[Player] = Storage[Player] or {}
- Storage[Player][Name] = Storage[Player][Name] or {
- startTime = workspace.DistributedGameTime,
- Duration = Duration or nil
- }
- end
- function module:AddCooldown(Player: Player, Name: string, Duration: number)
- module.new(Player, Name, Duration)
- if Duration then
- task.delay(Duration, function()
- if Storage[Player] then
- Storage[Player] = nil
- end
- end)
- end
- end
- function module:RemoveCooldown(Player: Player, Name: string)
- if Storage[Player] then
- Storage[Player][Name] = nil
- end
- end
- function module:OnCooldown(Player: Player, Name: string)
- local cooldownProfile = Storage[Player] and Storage[Player][Name]
- if not cooldownProfile then
- return false
- end
- if cooldownProfile then
- if workspace.DistributedGameTime - cooldownProfile.startTime > cooldownProfile.Duration then
- return false
- end
- return true
- end
- end
- function module:CleanUp(Player: Player)
- Storage[Player] = nil
- end
- Players.PlayerRemoving:Connect(function(player)
- module:CleanUp(player)
- end)
- return module
Advertisement
Add Comment
Please, Sign In to add comment