Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
1
What method are you using to count the badges. The API doesn’t appear to return a number of badges. Benbebop 1049 — 3y
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 Killerbot712 47 — 3y
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 Killerbot712 47 — 3y
0
Put all the values inside “data” into a table and use table.len or # to count the number of entries. Benbebop 1049 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 2 years ago

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

Ad

Answer this question