BadgeService:AwardBadge(userid, badgeid) returning false

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.

Do you meet these conditions?

Grants a Player a badge with the UserId and the badge ID. Rate limit: 50 + 35 * [number of users] per minute. In order to successfully award a badge:

  • The player must be presently connected to the game.

  • The player must not already have the badge (note that a player may delete an awarded badge from their profile and be awarded the badge again).

  • The badge must be awarded from a server-side Script or a ModuleScript eventually required by a Script, not from a LocalScript.

  • The badge must be awarded in a place that is part of the game associated with the badge.

  • The badge must be enabled; check this using the IsEnabled property of the badge fetched through BadgeService:GetBadgeInfoAsync().

Also as a code readability tip, use early returns!

1 Like

Let me add a few to that …
The place must be published to Roblox.
The badge must belong to the same game.
API services must be enabled.

Also you can’t get a badge if you already own it.

holy indentations

maybe the player already has the badge?
UserHasBadgeAsync
or maybe it’s disabled?
GetBadgeInfoAsync

  1. yes, the player is presently connected to the game. The whole loop checks first if the player exists before running all of this.
  2. I already have a check for that and it only runs for players who doesnt have the badge.
  3. Please read the whole post, I have already confirmed that it is ran on the server side.

Can you show more of your code then?

  1. Yes, the place is already published to Roblox. My players are having troubles regarding the obtainment of those badges.
  2. The badge belongs to the same game that the code is running on.
  3. API services are enabled, I am using Datastores in the same script and nothing is bugging out for it.
  4. The badge is being awarded in the main place of the game.
  5. 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.

Does it output any errors in console?

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.

there is absolutely no errors related to the while condition in the console, both in serverside and client side.

Hmmm, this may be a Roblox bug then if it’s just silently failing.

1 Like

thats what i thought too, maybe i should report the bug.

Programmers trouble shoot to find the problem.

Is HTTP Service enabled …

yes HTTP service is enabled, i am absolutely sure because the same game and the same script uses datastore which works just fine

I went back and tested later that day and mine worked again but, the notice didn’t show.