5Mdev
All Snippets
Lua Snippet

Server-Side Rate Limiter / Anti-Spam Wrapper

·Published 20 Aug 2026·1 likes·0 comments

Description & Usage

Shields server-side net events against trigger injectors by enforcing execution cooldowns per player source.

Source Code (2 Files)
1local executionCooldowns = {}
2
3local function RegisterRateLimitedEvent(eventName, cooldownMs, callback)
4 RegisterNetEvent(eventName, function(...)
5 local src = source
6 local now = GetGameTimer()
7
8 executionCooldowns[eventName] = executionCooldowns[eventName] or {}
9 local lastRun = executionCooldowns[eventName][src] or 0
10
11 if (now - lastRun) < cooldownMs then
12 DropPlayer(src, string.format("[Anti-Cheat] Trigger rate limit exceeded on: %s", eventName))
13 return
14 end
15
16 executionCooldowns[eventName][src] = now
17 callback(src, ...)
18 end)
19end
1 likes ·Sign in to like
0 discussion replies

Community Discussion (0)

Sign in to join the discussion and leave a comment.