So I’m working on this game where gaining currency primarily involves collecting items scattered across the map, there are other ways to gain this currency too but that’s not what I’m having issues with. What I’m having issues with is that I recently tried compiling all three badge giver scripts from workspace into the main data script that I had recently put into ServerScriptService (The data script itself still works fine); The badge givers do seem to work judging from the print() tests, although after a while of collecting I will get a ‘UserHasBadgeAsync: Too many requests’ message in the output coming from the data script.
local Players = game.Players
local badges = game:GetService("BadgeService")
local tsRuinsId = 2143851527
local fellRuinsId = 2149144835
local sansRoomId = 2924490344311046
local Funny = Instance.new 'BoolValue'
Funny.Name = 'leaderstats'
Instance.new('IntValue', Funny).Name = "LV"
Instance.new('IntValue', Funny).Name = "EXP"
Players.PlayerAdded:connect(function(Player)
local Stats = Funny:Clone()
Stats.Parent = Player
local Love = Stats.LV.Value
local Experience = Stats.EXP.Value
--Funny LOVE stuff
Stats.EXP.Changed:Connect(function()
if Stats.EXP.Value >= 5000 and not badges:UserHasBadgeAsync(Player.UserId, tsRuinsId) then
--badges:AwardBadge(Player.UserId, tsRuinsId)
print('ts ruins moment')
end
if Stats.EXP.Value >= 50000 and not badges:UserHasBadgeAsync(Player.UserId, fellRuinsId) then
--badges:AwardBadge(Player.UserId, fellRuinsId)
print('fell ruins moment')
end
if Stats.EXP.Value >= 1000000 and not badges:UserHasBadgeAsync(Player.UserId, sansRoomId) then
--badges:AwardBadge(Player.UserId, sansRoomId)
print('sans room moment')
end
--There's more to this code but it's mostly irrelevant to the issue at hand
As I said earlier, I did admittedly have three separate badge giver scripts for all three of the badges I want awarded, they all worked too but did the same error message thing after a while of collecting. I did compile them all together for optimization as I’ve currently been hard at work optimizing this game a lot more. So basically I was wondering if there is perhaps any way to get this to work AND not have the error message show up in the Output bar? Again it works perfectly fine according to playtests, the only issue is that ‘Too many requests’ message that pops up after a while of collecting. Any advice?
First of all, the reason why you’re getting “Too many requests” as an error is because you are sending too many requests to roblox’s servers.
You could probably cache the badges they don’t have, and keep the cache stored so you don’t send as many requests. Using “UserHasBadgeAsync” is getting fired several times and is resulting in that.
Do you still have the other scripts tucked somewhere else in the game? If you’ve got more than just the one script checking for badges it might be the problem. I’ve done it where I’ve accidentally copied a script into the workspace from another location so it’s causing issues like this.
You can check if you go to the View tab in Studio and select the Find all/Replace all tool and type in UserHasBadgeAsync to show where you’ve used it in scripts.
I worked at the issue a little bit more after posting this, what you said does make a lot of sense!
Though I did do away with having the badge giver scripts be inside the stats script and instead opted to have it be it’s own script, being an edited version of the first three that I had going on before but with all of them being compiled together into one big script.
local souls = "EXP"
local value = 5000
local value2 = 50000
local value3 = 1000000
local badgeid = 2143851527
local badgeid2 = 2149144835
local badgeid3 = 2924490344311046
local badgeService = game:GetService("BadgeService")
game.Players.PlayerAdded:connect(function(p)
repeat task.wait() until p:findFirstChild("leaderstats") ~= nil
p.leaderstats[souls].Changed:connect(function()
if p.leaderstats[souls].Value <= value - 1 then return end
if p.Character.Humanoid.hasTSBadge.Value == false then
p.Character.Humanoid.hasTSBadge.Value = true
game:GetService("BadgeService"):AwardBadge(p.userId, badgeid)
end
if p.leaderstats[souls].Value <= value2 - 1 then return end
if p.Character.Humanoid.hasFellBadge.Value == false then
p.Character.Humanoid.hasFellBadge.Value = true
game:GetService("BadgeService"):AwardBadge(p.userId, badgeid2)
end
if p.leaderstats[souls].Value <= value3 - 1 then return end
if p.Character.Humanoid.hasSansRoomBadge.Value == false then
p.Character.Humanoid.hasSansRoomBadge.Value = true
game:GetService("BadgeService"):AwardBadge(p.userId, badgeid3)
end
end)
end)
--This script is an edited version of another script by Skeletronaion from the Toolbox
As you can see I also opted out of having the ‘UserHasBadgeAsync’ thing entirely; rather I put three BoolValues inside the Humanoid in StarterPlayer so that whenever the player reaches a certain amount, that certain value will get ticked off preventing an overflow in the console. Thank you for the advice! ^ ^
No problem, just don’t forget to close the post. I forgot to mention that you could use “has user badge” but you’d have to use it sparingly. The method you used also works fine, just was hoping to let you know what that originally meant .
I’m not exactly sure how to close posts on here, I’ve looked around on the topic itself but I couldn’t really find anything aside from a trash button that I guess I need a certain rank to do.