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
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