Skip to content

Instantly share code, notes, and snippets.

@evaera
Last active November 15, 2023 16:28
Show Gist options
  • Save evaera/4ea10bf3cc8cb530b22e85485ab3f789 to your computer and use it in GitHub Desktop.
Save evaera/4ea10bf3cc8cb530b22e85485ab3f789 to your computer and use it in GitHub Desktop.
Roblox Lua throttle
function throttle(func, seconds)
local lastCalled = 0
local callNumber = 0
return function(...)
callNumber = callNumber + 1
local currentCallNumber = callNumber
if tick() - lastCalled < seconds then
wait(seconds - (tick() - lastCalled))
if callNumber ~= currentCallNumber then
return
end
end
lastCalled = tick()
return func(...)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment