Forest Logo
search
package_2

ratemanager

By @krazeems

Roblox

Mirrored

🔁 RateManager

A lightweight utility for handling cooldowns and rate limits in Roblox Lua.

Debounce, rolling limits, queueing, pause/resume, and more: all in one clean module.


🚀 Features

  • ⏱️ Debounce (classic cooldown)
  • 🔁 RateLimit (e.g. 10 calls per 60 seconds)
  • 🧱 Optional call queueing (RateLimit only)
  • ⏸️ Pause & Resume
  • 🔄 Manual Reset() and Cancel() (with queue control)
  • 🔔 Signals: OnReset, OnLimitHit
  • 📦 Self-contained, no external dependencies
  • 🧼 MIT licensed

📦 Installation

Manual
  1. Drop RateManager.lua into your project (e.g. ReplicatedStorage.Packages)
  2. Require it in your scripts:
local RateManager = require(game.ReplicatedStorage.Packages.RateManager)
Wally (Recommended)

Add RateManager as a dependency in your wally.toml:

[dependencies]
ratemanager = "krazeems/ratemanager@1.0.0"

Then run in your terminal:

wally install

This downloads RateManager (including bundled Signal) to your wally_modules folder.

Rojo

Make sure your default.project.json (or .rojo.json) includes RateManager so Rojo syncs it to Roblox:

{
  "name": "MyProject",
  "tree": {
    "$className": "Folder",
    "ReplicatedStorage": {
      "$className": "Folder",
      "RateManager": {
        "$path": "wally_modules/krazeems/ratemanager/RateManager"
      }
    }
  }
}

Adjust the $path if you use manual installation or a different directory.

Require in your code
local RateManager = require(game:GetService("ReplicatedStorage"):WaitForChild("RateManager"))

🔨 Example Usage

🕒 Debounce (Cooldown that ignores spam)

local cooldown = RateManager.new(2) -- 2 second cooldown

button.MouseButton1Click:Connect(function()
	cooldown:Execute(function()
		print("Clicked!") -- Fires once every 2 seconds max
	end)
end)

🔁 RateLimit (e.g. 5 calls per 10 seconds)

local limiter = RateManager.new(5, 10, RateManager.Mode.RateLimit)

RunService.Heartbeat:Connect(function()
	limiter:Execute(function()
		print("Allowed!")
	end)
end)

🧱 Queueing (for RateLimit)

limiter:SetQueueEnabled(true)

Excess calls will be queued instead of dropped


⏸️ Pause / Resume

limiter:Pause()
wait(5)
limiter:Resume()

⚠️ Reset vs Cancel

cooldown:Reset()      -- Ends timer and fires OnReset
cooldown:Cancel()     -- Ends timer silently

cooldown:Reset(true)  -- Ends and clears queued calls (RateLimit only)
cooldown:Cancel(true) -- Cancels and clears queue (no OnReset)

🔔 Events

cooldown.OnReset:Connect(function()
	print("Cooldown/rate limit reset!")
end)

cooldown.OnLimitHit:Connect(function()
	print("Call was blocked (cooldown active or limit hit)")
end)

📚 API

RateManager.new(delayOrMaxCalls: number, perSeconds?: number, mode?: RateManager.Mode) → RateManager
MethodDescription
:Execute(func, ...)Executes the callback if allowed
:Reset(dropQueuedCalls?)Ends cooldown/rate window and fires OnReset
:Cancel(dropQueuedCalls?)Ends it silently, skips OnReset
:Pause() / :Resume()Temporarily pause/resume timer logic
:IsOnCooldown()Returns true if currently blocked
:GetTimeLeft()Returns remaining cooldown time (in seconds)
:SetQueueEnabled(enabled: bool)Enables queueing (RateLimit mode only)
:Destroy()Cleans up signals and state
EventDescription
OnResetFires when timer or rate window is reset
OnLimitHitFires when a call is blocked by cooldown

📎 Links


🧩 Final Notes

RateManager was built to simplify cooldown and rate-limiting logic in Roblox without bloating your code. It’s clean, event-based, and flexible for nearly any input-related system.

Suggestions and contributions are always welcome.

Package Details

Install command (Click to copy)


Version

1.0.0

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.