while wait(10) do
for i,v in pairs(game.Players:GetChildren()) do
if v.leaderstats.Stage.Value >= 115 then
if not game:GetService("BadgeService"):UserHasBadgeAsync(v.UserId,2125468623) then
game:GetService("BadgeService"):AwardBadge(v.UserId,2125468623)
end
end
end
end
I’m under the impression that this is probably a general error on Roblox’s side. Async anything has the ability to throw errors like this on occasion. Is this error happening after a certain amount of time? It might be better to simply detect when someone changes stages, instead of doing it every 10 seconds.
An easy way to mitigate this would be wrapping this in a pcall as well.
Yeah, honestly it might be easier to just only fire the loop if they are exactly 115 and then check whenever someones stage value changes (this might be an issue though, as you could end up missing someone on the occasion it errors). Or, add some logic in there that if they are above 115, and they have gotten the badge before, the game wont check for them anymore.
Either way the main thing you’ll want to do is reduce the amount of calls.
local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 2125468623
game.Players.PlayerAdded:Connect(function(Player)
Player.leaderstats.Stage.Changed:Connect(function()
if Player.leaderstats.Stage.Value >= 115 then
local success,result = pcall(userHasBadge,badges,Player.UserId,badgeId)
if success then
if not result then
badges:AwardBadge(Player.UserId,badgeId)
end
end
end
end)
end)
local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 2125655691
game.Players.PlayerAdded:Connect(function(Player)
Player:WaitForChild("leaderstats").Stage.Changed:Connect(function()
if Player.leaderstats.Stage.Value >= 115 then
local success,result = pcall(function()
return userHasBadge,badges,Player.UserId,badgeId
end)
if success then
--code
end
end
end)
end)
The script provided has that implemented already. You can refer to below if needed!
if Player.leaderstats.Stage.Value >= 115 then -- anyone who has a value of 115 or more
if Player.leaderstats.Stage.Value == 115 then -- anyone whos value is exactly 115
if Player.leaderstats.Stage.Value > 115 then -- anyone who is above 115
if Player.leaderstats.Stage.Value <= 115 then -- anyone who is less than or equal to 115
if Player.leaderstats.Stage.Value < 115 then -- anyone who is less than 115
Are you testing this in Studio? You’re unable to award badges in studio. If you have a higher stage and you’re testing it on yourself, try it in the actual Roblox game.
local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 2125468623
game.Players.PlayerAdded:Connect(function(Player)
Player:WaitForChild("leaderstats").Stage.Changed:Connect(function()
if Player.leaderstats.Stage.Value >= 115 then
local success,result = pcall(function()
return userHasBadge,badges,Player.UserId,badgeId
end)
if success then
--code
end
end
end)
end)