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

How would I get the exact amount of a badges a player has with httpservice?

Hello, I'm trying to make a badge counter like the one in this (http://www.roblox.com/games/5166670285) game.

But when I use it, it gets something like 32,500 instead of 32,452. If anybody could help it would be very much appreciated

heres my code

local httpservice = game:GetService("HttpService")

game.Players.PlayerAdded:Connect(function(p)
	local url = "https://badges.rprxy.xyz/v1/users/"..p.UserId.."/badges?limit=100&sortOrder=Asc"
	while true do
	
		local request = httpservice:JSONDecode(httpservice:GetAsync(url))
		local cursor = request.nextPageCursor
		if cursor == "null" then
			break
		else
	url = "https://badges.rprxy.xyz/v1/users/"..p.UserId.."/badges?limit=100&sortOrder=Asc&cursor="..cursor
	p.leaderstats.Badges.Value += 100
end

end
end)

4 comments

1

What method are you using to count the badges. The API doesn’t appear to return a number of badges.

0

the api returns a list of badges and a next page cursor. the next page cursor makes a 2nd list of 100 badge that the user has been awarded. So i am just counting 100 per a request

0

But the user probably doesnt have a badge count in the multiples of 100. So i am trying to get how many badges there is on the final list

0

Put all the values inside “data” into a table and use table.len or # to count the number of entries.

1 answer

That's what happened to me quite a bit, as you see you are using += 100 and when it reaches the last page it won't add the value, it will add 100...

Basically you just need to add the total inside the page...

iirc, p.leaderstats.Badges.Value += #request.body or #request?

Note: Badges api no longer works for anyone who comes across this 5/18/21

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