BadgeService:CheckUserBadgesAsync gives error

I have this code on the client that checks what badges a player has all the badges in my game. All badges are from my game. In total there are 35 badges. It worked fine for years, but recently I have gotten bug reports that it errors. The error I get is: CheckUserBadgesAsync: Challenge is required to authorize the request. Why does this happen?

This is my code, and I run it on a client once when they join the server:

local allbadges = {'array of all badges in my game'}
if player.UserId > 0 then
		local badgessplit = {}
		local currentarr = {}
		for i,v in pairs(allbadges) do
			if i ~= 1 and (i%10 == 1) then
				table.insert(badgessplit,table.clone(currentarr))
				table.clear(currentarr)
			end
			table.insert(currentarr,v)
			if i == #allbadges then
				table.insert(badgessplit,table.clone(currentarr))
			end
		end
		for i=1,#badgessplit do
			local hasbadges = game.BadgeService:CheckUserBadgesAsync(player.UserId,badgessplit[i])
			for _,v in pairs(hasbadges) do
				menufolder.Badgeprogression.ImageLabel.ScrollingFrame[tostring(v)].BadgeContainer.Locked:Destroy()
			end
		end
	end	
1 Like

This is what I was able to find from the documentation:

  1. This method accepts a maximum of 10 badges per call, so if you have more you need to split them to 10 badge batches (sub-arrays).
  2. For LocalScripts specifically the user id must match that of the local client, else the API will fail. If you want to check batches of other players you need to use a server script, if you want the client to initiate the call connect it to a remote event or function.

On top of this you should check the following recent forum posts that mentions upcoming breaking changes on the behavior of the call you are having issues with:

Specifically that post mentions that:

  1. If the user id is not in the server for a while
  2. and also the badges you are checking aren’t owned by the current experience

Then it may prevent you from checking them.

  1. I know that I need to split it up in batches of 10, thats what my code does.
  2. It matches the clients ID. Like I said, it worked before. but not now.

I also did check that post, but all badges are from the same game that the script is in. It checks badges of a player that is in the server, so according to that post nothing should break.

Have you checked if it works in-game or in a studio test (the ones with the dummy player accounts)? Maybe it’s Roblox being a mess because it sees the request as a request coming from Roblox studio instead of their servers.

You mention you have gotten bug reports, are you sure these occur 100% of the time (not edge cases you can pcall) and they are the error you mention in the post?