Okay so, yes I do know how to make debounces, however this is tricky. What if I wanna make a debounce like 30 requests per minute? I tried everything and no luck, here’s my current code
local cooldown = os.time()
local function sendrequest(url,data)
if os.time() - cooldown > 60 then
httpservice:PostAsync(url,data)
cooldown = os.time()
end
end
Make a variable counter for and every request add 1 to the variable. Then put a if statement if the request already filled up(has 30 request) then debounce it for 1 min. Then use a remotefunction to return to alarm the user that the queue already filled up so they can’t run his request yet.
According to this thread, the max limit is 500. And i assume there will be alot of servers in the future on your game, so i recommend you using pcall if the request was accepted.
local debounce = true
local requests = 0
local function sendrequest(url,data)
if requests < 30 and debounce == true then
requests += 1
httpservice:PostAsync(url,data)
task.wait(1)
debounce = true
end
end
while task.wait(60) do
requests = 0
end
Here’s a more reliable/efficient version which doesn’t rely on an indefinite loop which yields the entire script.
local Http = game:GetService("HttpService")
local Debounce = false
local Requests = 0
local ProtectedCall = pcall
local Tick = tick
local Time = Tick()
local function SubmitRequest(URL, Data)
if Debounce then
return
end
Debounce = true
task.delay(0.1, function()
Debounce = false
end)
if tick() - Time > 60 then
Time = Tick()
Requests = 0
end
Requests += 1
if Requests > 30 then
return
end
local Success, Result = ProtectedCall(function()
return Http:PostAsync(URL, Data)
end)
if Success then
print(Result)
--Do something with the response of the http request here.
return Result
else
warn(Result)
end
end
local debounce = true
local requests = 0
local function sendrequest(url,data)
if requests < 30 and debounce == true then
requests += 1
httpservice:PostAsync(url,data)
task.wait(1)
debounce = true
end
end
task.spawn(function()
while task.wait(60) do
requests = 0
end
end)