Back to community

Tiny helper: throttle any net event in 6 lines

124 rep268 views1 min read

Pasted into every project I touch:

local lastFire = {}
function isThrottled(src, event, intervalMs)
    local key = src .. ':' .. event
    local now = GetGameTimer()
    if lastFire[key] and (now - lastFire[key]) < intervalMs then return true end
    lastFire[key] = now
    return false
end

Usage:

RegisterNetEvent('shop:buy', function(itemId)
    local src = source
    if isThrottled(src, 'shop:buy', 500) then return end
    -- handle buy
end)

Catches 99% of "client spams the same event" exploits. Clean it up periodically with SetInterval(function() lastFire = {} end, 600000) if you want to avoid memory creep.

Not glamorous, but I've stopped 4-5 dupe exploits in the wild with literally this.

31 1 commentsSign in to vote

Comments (1)

Sign in to leave a comment.
  • Add a per-source attempt counter and you can auto-flag for review at e.g. 50 throttled hits in a minute. That's how I caught a duper last month.

    6 points