Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my badge awarder script spam the output with "TooManyRequests"?

Asked by 3 years ago

I'm making a tag game, and I have a script that should award a badge if you tag a developer, and kill you if you're tagged. It uses tools. But, after this new update with a badge, it spams the output/dev console with "TooManyRequests". Please help!

local Humanoid = script.Parent:WaitForChild("Humanoid")

function award(plr)
    if not game.BadgeService:UserHasBadgeAsync(plr.UserId, 2124571974) then
        game.BadgeService:AwardBadge(plr.UserId, 2124571974)
    end
end

script.Parent.Torso.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local currentplayer = game.Players:GetPlayerFromCharacter(script.Parent)
    if player then 
        if hit.Parent.Name == "Tool" then
            Humanoid:TakeDamage(1000000)
        end
        if player.UserId == 111255307 then
            award(currentplayer)
        elseif player.UserId == 424716966 then
            award(currentplayer)
        elseif player.UserId == 109352342 then
            award(currentplayer)
        end
    end
end)
while true do
    wait(0.1)
    Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end

1
the Touched event may fire multiple times in a very short amount of time so if all the requirements are met (the right userId) etc the award function will then try and award the badge a bunch of times in a very short amount of time, hence why your probably getting this error. PURGATORYAGENT_1 43 — 3y

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

Well I can’t review the code too much as I’m on my phone, but this is most likely because the script is running multiple times every time the Player moves on the brick, to fix this, use a debounce which only runs the code once each designated amount of time.


local Humanoid = script.Parent:WaitForChild("Humanoid") local Debounce = false function award(plr) if not game.BadgeService:UserHasBadgeAsync(plr.UserId, 2124571974) then game.BadgeService:AwardBadge(plr.UserId, 2124571974) end end script.Parent.Torso.Touched:Connect(function(hit) if debounce = false then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) local currentplayer = game.Players:GetPlayerFromCharacter(script.Parent) if player then if hit.Parent.Name == "Tool" then Humanoid:TakeDamage(1000000) end if player.UserId == 111255307 then award(currentplayer) elseif player.UserId == 424716966 then award(currentplayer) elseif player.UserId == 109352342 then award(currentplayer) end end wait(3) debounce = false end) while true do wait(0.1) Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None end
Ad

Answer this question