there is a loop in my game that periodically gives out badges to players in the server side if certain conditions were met. However, BadgeService seemingly refuses to give the badge(s).
while task.wait(5) do
if player then
Badges = GameData.Badges
TotalQuarks = GameData.Stats.TotalQuarks
Level = GameData.Currencies.WavelengthLevel
local badgeConditions = {
{id = 437279698252099, condition = function() return TotalQuarks >= 2500 end},
{id = 2796340870173761, condition = function() return TotalQuarks >= 7500 end},
{id = 1574183038473179, condition = function() return TotalQuarks >= 15000 end},
{id = 3432093508098186, condition = function() return not Bnum.lt(Level, c1) end},
{id = 567320515783474, condition = function() return not Bnum.lt(Level, c2) end},
{id = 3891287698695544, condition = function() return not Bnum.lt(Level, c3) end}
}
for _,v in badgeConditions do
if v.condition() then
for _,vv in Badges do
if vv[1] == v.id and vv[2] then
local res = game.BadgeService:AwardBadge(player.UserId, v.id)
print(res)
if res then
ReplicatedStorage.Events.Award:FireClient(player, v.id)
end
task.wait(5)
end
end
end
end
else
break
end
end
the print line always print false, meaning the badge wasn’t given. I have tested the code both in studio and in a public server, a private server, and nothing seem to work. Ive also printed out every single variable present in this snippet of code, and they were all valid. My UserId is valid, v.id is also valid, i tried copying the asset id directly from the badge tab in create.roblox.com, and the ids from both sides are identical.
PS: Bnum is a bignumber module, Bnum.lt(a,b) is the same as a < b. I have also purposefully remove a specific badge from my inventory, that is included in one of the six badges in this loop, and it still doesnt give me the badge.
Yes, the place is already published to Roblox. My players are having troubles regarding the obtainment of those badges.
The badge belongs to the same game that the code is running on.
API services are enabled, I am using Datastores in the same script and nothing is bugging out for it.
The badge is being awarded in the main place of the game.
The badge is already enabled, I have checked in both create.roblox.com and with the command. In fact, I use :GetBadgeInfoAsync() to display the badge informations in a part of the game.
I am afraid i cant show you more parts of the code, since the problem is all inside this while loop. The problem is not with the conditions being false either, but rather the AwardBadge not being executed properly at all. The print command (print(res)) do print, but theyre all false.