So I’m trying to make an overhead where it says how many badges you have, but i can’t find any API that counts all of a player’s badges,
I found this API but its inaccurate
There is games that counts all of the badges you have so I’m kind’ve confused on how they do it
and also i have over 8000+ badges so i don’t really know.
What you could do is when a Player is Added, go through each badge detecting if they have it or not. Every time the code detects they do own a badge you increment a specific value +1. When the code is complete you can simply display that value where ever you please.
May not be the most efficient way, especially having 8000 badges as you said. If no API exist for this specific scenario then this could be your only route.
I made a way of counting badges but its far too slow. You would require a proxy, likely rprxy.xyz to fetch data from roblox. It takes me 15 minutes to get all my 16k badges… I don’t know how this game made it so fast. I tried sending 2 requests at a time… 🎖️12,003 Badge Walk🎖️ Free Badges - Roblox
The fastest I created the badge count was in 5 minutes… Still too long and that was because I was using spawn(function() which is terrible.
I can’t find the docs for it, but here’s what all the query strings mean:
assetTypeId:
the asset type’s id, 21 for badges
cursor:
current cursor, don’t put anything at first and change it to the nextPageCursor of previous query
itemsPerPage:
maximum of 100, how many badges it loads per page
userId:
the UserId of whoever you’re getting the badges of (duh)
You can’t get a direct total, so you would have to iterate through a bunch of pages and total it up. The maximum page size is 100 as well, so it’ll be a bit annoying to do. You can’t even queue up web requests using coroutines, since you need the cursor from the previous page.
Basically there is a “cursor” when you send a get request to the endpoint. The cursor allows you to go to the next page… I think they must have got all the data from the last page and the first page then moved to the next page and the previous page making it much faster, aka x2 speed badge collection algorithm. I haven’t tried this method but it should be super fast.
The cursor is used to get the next page of badges. Add each badge to the count.
Sticky, the project was cancelled so i didn’t get a chance to fully make it but, i just made a proxy then made it access the target’s badges – end of what i’ve done
what i was gonna do:
it reads the cursor so it goes to the next page
counts the ids then add the ids as a number
Here’s an implementation I just wrote which achieves this.
local http = game:GetService("HttpService")
local get = http.GetAsync
local jsonDecode = http.JSONDecode
local proxyUrl = "roproxy.com"
local baseUrl = "https://badges."..proxyUrl.."/v1/users/%d/badges?limit=100&sortOrder=Asc&cursor=%s"
local maxTries = 5
local function getUsersBadgeCountRecursive(userId, badgeCount, cursor, cache)
badgeCount = badgeCount or 0
cursor = cursor or ""
cache = cache or {}
if cache[cursor] then cache[cursor] += 1 else cache[cursor] = 1 end
if cache[cursor] >= maxTries then return end
local requestUrl = string.format(baseUrl, userId, cursor)
local success, result = pcall(get, http, requestUrl)
if success then
if result then
local success2, result2 = pcall(jsonDecode, http, result)
if success2 then
if result2 then
cursor = result2.nextPageCursor
if cursor then
badgeCount += 100
return getUsersBadgeCountRecursive(userId, badgeCount, cursor, cache)
else
badgeCount += #result2.data
return badgeCount
end
end
else
warn(result2)
end
end
else
warn(result)
end
task.wait(1)
return getUsersBadgeCountRecursive(userId, badgeCount, cursor, cache)
end
local badgeCount = getUsersBadgeCountRecursive(261) --Shedletsky's ID.
print(badgeCount) --867