HTTP 429 every time I make a web request

image

Hi, I made a button that can upload to a Discord webhook but it’s limited to once every 30 seconds at most. However, literally on the first test of this I got the error above. I had never even touched the button before that, so it makes no sense to me why I’m getting rate limited. What can I do to fix this? Thanks!

To add on to this, it happens when there have been 0 HTTP requests.

It might be something to do with the methodology used in your script. Could you post us some of the contents of your scripts so we can help debug the issue?

model.GameEnd.ClickDetector.MouseClick:Connect(function(plr)
	if canPlayerUseEvents(plr) and not cooldown then
		local s,e = pcall(function()
			local info = {
				embeds = {
					{
						title = "GAME END:";
						description = "VANCOUVER HUSKIES "..values.one.Value.." - "..values.two.Value.." "..awayName:upper();
						color = red;
						footer = {
							text = os.date()
						}
					}
				}
			}
			info = HttpService:JSONEncode(info)
			HttpService:PostAsync(webhookUrl, info)
		end)
		if not s then
			warn(e)
			local msg = Instance.new("Message", plr:WaitForChild("PlayerGui"))
			msg.Text = "There was an error uploading."
			Debris:AddItem(msg, 5)
		else
			cooldown = true
			local msg = Instance.new("Message", plr:WaitForChild("PlayerGui"))
			msg.Text = "Successfully uploaded!"
			Debris:AddItem(msg, 5)
			wait(30)
			cooldown = false
		end
	end
end)

That’s one of the buttons that will make web requests, and it’s throwing an error every time. The 30 second cooldown was working; I tested that.

Whats the content of the function canPlayerUseEvents(plr)?

It checks that the player is on a certain team and returns if they are able to use the button.

function canPlayerUseEvents(plr)
	if plr.Team then
		if plr.Team.Name == "DJ" or plr.Team.Name == "Broadcasting" then
			return true
		end
	end
	coroutine.resume(coroutine.create(function()
		local msg = Instance.new("Message", plr:WaitForChild("PlayerGui"))
		msg.Text = "You must be teamed DJ or Broadcaster to use this!"
		Debris:AddItem(msg, 5)
	end))
	return false
end

What I am assuming upon inspection is your likely having a debounce error in accordance with how the cooldown works. Seeming as posting to the website can take some time (minut yes, but still relatively plausible), it might be that your cooldown isn’t working correctly. I would generally do a more accurate time check, and an entire debounce for the function like so:

local debounce = false
local cooldown = tick() - 30 -- now the function is automatically useable

model.GameEnd.ClickDetector.MouseClick:Connect(function(plr)
	if not debounce then -- this just prevents someone double clicking and messing up our theory
		debounce = true
		if canPlayerUseEvents(plr) and ((tick() - cooldown) > 30)  then -- this is actually 30 seconds now
			local s,e = pcall(function()
				local info = {
					embeds = {
						{
							title = "GAME END:";
							description = "VANCOUVER HUSKIES "..values.one.Value.." - "..values.two.Value.." "..awayName:upper();
							color = red;
							footer = {
								text = os.date()
							}
						}
					}
				}
				info = HttpService:JSONEncode(info)
				HttpService:PostAsync(webhookUrl, info)
			end)
			if not s then
				warn(e)
				local msg = Instance.new("Message", plr:WaitForChild("PlayerGui"))
				msg.Text = "There was an error uploading."
				Debris:AddItem(msg, 5)
			else
				cooldown = tick()
				local msg = Instance.new("Message", plr:WaitForChild("PlayerGui"))
				msg.Text = "Successfully uploaded!"
				Debris:AddItem(msg, 5)
			end
		end
		debounce = false
	end
end)

I’ll test that out and report back on if it works. Thanks!

The same behavior is still happening. In some servers, I join and it immediately says “Too many requests”. But when I restart the server it uploads correctly.