Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

is there an API (even if depricated) to see badges a player has?

I've looked everywhere including the Developer Hub, DevForum, Fandoms, Reddit, and many more sites, I can't find anything.. is it possible to see a player's badges?

2 comments

0

BadgeService:UserHasBadge

1

He said how to see a player's badges.

1 answer

✓ Accepted answer

You can't "see" a player's badges, but you can request to see their info on a specific badge using UserHasBadgeAsync.

This would require you to have the player's UserId, and also the ID of the badge you want to check for, and while you could technically list all of a players badges by brute forcing it in a loop, it might take literal days to go through all of them.

You also can get the info of each badge by using GetBadgeInfoAsync

Anyway, to do it, you would use the "BadgeService":


local Players = game:GetService("Players")
	local BadgeService = game:GetService("BadgeService")
	local badges = {}
	for i=1,#badges do
		print(badge[i], BadgeService:UserHasBadgeAsync(player.UserId, badge[i]),GetBadgeInfoAsync(badge[i]))
	end

And here is the very much more complicated way:

local HTTP = game:GetService"HttpService"

local function getPlayerBadgeInfo(userId,BadgeLimit)
	
	local badges = HTTP:GetAsync("https://badges.rprxy.xyz/v1/users/" .. userId .. "/badges?limit=" .. BadgeLimit .. "&sortOrder=Asc")
	local badgeTable = string.split(badges,"},{")
	table.remove(badgeTable,1)--removes data from the page that doesn't have to do with badges
	for i=1,#badgeTable do
		print(badgeTable[i].."\n\n")
	end
end

getPlayerBadgeInfo(1216143118,10)

Explanation:

So the only part that you really need here is this line:

local badges = HTTP:GetAsync("https://badges.rprxy.xyz/v1/users/" .. userId .. "/badges?limit=" .. BadgeLimit .. "&sortOrder=Asc")

It returns a string that comes from the badge pages of a specified userId, that only includes the max (BadgeLimit) amount of badges specified. It goes in ascending order, so the user's first badge to their newest badge.

These next two lines are probably as good as I can get it to separate each badge (JSONDecode doesn't work). I at first had split it by "id", but that added on extra characters that were unneeded and sometimes split descriptions in half, so I got rid of it. I changed it to "},{" because that would mean that since each badge is a table of data, it would now split by each badge. This will only need to be changed if in the future there are properties of badges that have 2 tables next to each other.

local badgeTable = string.split(badges,"},{")
table.remove(badgeTable,1)--removes data from the page that doesn't have to do with badges

Then this part is simple, it prints the data between each id with 2 lines in between for easier readability.

for i=1,#badgeTable do
	print(badgeTable[i].."\n\n")
end

so it was a bit difficult for me to test because printing the output printed the whole thing as a single string, but I did get the data displayed somewhat manageable here.

13 comments

0

well a disappointing fact, but i guess there's really no way.. so is there a way to get all the badges of a game instance?

0

Are you talking about a game that you don't own? or one that you do?

0

the one you own,.

0

Well, the simplest answer would be to store them in a table, but I also may have another way of doing this, I just need to do a bit of testing on my own before I can be sure.

0

alright, can you test then lemme know of the results? please

0

That should work, the ID I chose was one of my friends. I just wanted to make sure you were able to search anyone.

0

alright, i'll play around with it.. Thank you

0

I went further in depth with my explanation too.

0

Thank you.. i also didn't know the fact that table.split was added to the table library..

0

Oh also, if you do testing, make sure you do it on someone who has a low number of badges because it will be easier to handle. I tried to do it on myself at first, but it wasn't fun because I have 38 pages of badges I've collected over the years.

0

i just noticed the fact that i can use HTTPService:JSONDecode(), and learned the fact that you can only input 10, 25, 50, and 100 for the limit parameter in the URL

0

I tried using JSONDecode, but it wasn't returning anything to me for some reason

0

oh i see

This discussion is preserved as it was. New answers, comments, and votes are closed.