I have this badge script that is supposed to check for when a player’s stats have changed, and, if the player’s stats reached a certain point, give them a badge if they don’t already have it.
However, even with these checks, it apparently doesn’t work and overflows the HTTP service system, which affects other things in the game. No one in the servers of my game I’ve entered has reached the necessary requirements to get the badge, so it shouldn’t be checking for it.
Here’s the code:
local bdg = game:GetService("BadgeService")
local mkt = game:GetService("MarketplaceService")
game.Players.PlayerAdded:connect(function(p)
local temp = p:WaitForChild("temp", 2)
local stats = p:WaitForChild("leaderstats", 2)
stats.Money.Changed:connect(function() -- money rewards
if stats.Money.Value >= 250000 then
if not mkt:PlayerOwnsAsset(p, 2124443166) then
bdg:AwardBadge(p.userId, 2124443166) --- big bucks
end
elseif stats.Money.Value >= 7500000 and temp.Kills.Value >= 500 then
if not mkt:PlayerOwnsAsset(p.userId, 2124443165) then --nuclear player
bdg:AwardBadge(p.userId, 2124443165)
end
end
end)
end)
Here’s a screenshot of the in-game dev console output:
In the changed event, replace the line with the API request to if not cache.BADGE_NAME then (Replace BADGE_NAME with either big_bucks or nuclear_player).
When the player earns a badge, set cache.BADGE_NAME to true (again replacing BADGE_NAME).
Full Script
local bdg = game:GetService("BadgeService")
game.Players.PlayerAdded:connect(function(p)
local cache = {
big_bucks = bdg:UserHasBadgeAsync(p.UserId, 2124443166),
nuclear_player = bdg:UserHasBadgeAsync(p.UserId, 2124443165)
}
local temp = p:WaitForChild("temp") -- Remove the timeout, as it will only cause an error if the "temp" value fails to exist in 2 seconds.
local stats = p:WaitForChild("leaderstats")
stats.Money.Changed:connect(function() -- money rewards
if stats.Money.Value >= 250000 then
if not cache.big_bucks then
bdg:AwardBadge(p.userId, 2124443166) --- big bucks
cache.big_bucks = true
end
elseif stats.Money.Value >= 7500000 and temp.Kills.Value >= 500 then
if not cache.nuclear_player then --nuclear player
bdg:AwardBadge(p.userId, 2124443165)
cache.nuclear_player = true
end
end
end)
end)
local bdg = game:GetService("BadgeService")
game.Players.PlayerAdded:connect(function(p)
local temp = p:WaitForChild("temp", 2)
local stats = p:WaitForChild("leaderstats", 2)
local cache = {
big_bucks = bdg:UserHasBadgeAsync(p.UserId, 2124443166),
nuclear_player = bdg:UserHasBadgeAsync(p.UserId, 2124443165)
}
stats.Money.Changed:connect(function() -- money rewards
if stats.Money.Value >= 250000 then
if not cache.big_bucks then
bdg:AwardBadge(p.userId, 2124443166) --- big bucks
cache.big_bucks = true
end
elseif stats.Money.Value >= 7500000 and temp.Kills.Value >= 500 then
if not cache.nuclear_player then --nuclear player
bdg:AwardBadge(p.userId, 2124443165)
cache.nuclear_player = true
end
end
end)
end)