kodan

Untitled

Sep 29th, 2025
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local module = {}
  4.  
  5. local Storage = {}
  6.  
  7. function module.new(Player: Player, Name: string, Duration: number)
  8.  
  9. Storage[Player] = Storage[Player] or {}
  10.  
  11. Storage[Player][Name] = Storage[Player][Name] or {
  12. startTime = workspace.DistributedGameTime,
  13. Duration = Duration or nil
  14. }
  15. end
  16.  
  17. function module:AddCooldown(Player: Player, Name: string, Duration: number)
  18. module.new(Player, Name, Duration)
  19.  
  20. if Duration then
  21. task.delay(Duration, function()
  22. if Storage[Player] then
  23. Storage[Player] = nil
  24. end
  25. end)
  26. end
  27. end
  28.  
  29. function module:RemoveCooldown(Player: Player, Name: string)
  30. if Storage[Player] then
  31. Storage[Player][Name] = nil
  32. end
  33. end
  34.  
  35. function module:OnCooldown(Player: Player, Name: string)
  36.  
  37. local cooldownProfile = Storage[Player] and Storage[Player][Name]
  38.  
  39. if not cooldownProfile then
  40. return false
  41. end
  42.  
  43. if cooldownProfile then
  44. if workspace.DistributedGameTime - cooldownProfile.startTime > cooldownProfile.Duration then
  45. return false
  46. end
  47. return true
  48. end
  49. end
  50.  
  51. function module:CleanUp(Player: Player)
  52. Storage[Player] = nil
  53. end
  54.  
  55. Players.PlayerRemoving:Connect(function(player)
  56. module:CleanUp(player)
  57. end)
  58.  
  59. return module
Advertisement
Add Comment
Please, Sign In to add comment