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

How do I make a script that counts every badge that a player owns and display it?

Asked by
OX_X4 2
4 years ago

so i have this script it gets about 100 badges from the player and in one post a guy said to use a loop and i also dont know how to change the data to int value.

here is the code:

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local badges = Instance.new("IntValue", leaderstats)
        badges.Name = "Badges"
    local Http          = game:GetService("HttpService");
    local fetchBadges   = function(userId, badgeLimit)
        local Badges    = Http:GetAsync("https://badges.rprxy.xyz/v1/users/" .. userId .. "/badges?limit=" .. badgeLimit .. "&sortOrder=Asc")
        print(Badges)
        toReturn  = tonumber(Badges);
        return toReturn
    end;
    fetchBadges(player.userId, 100)
    badges.Value = toReturn
end)

1 answer

Log in to vote
0
Answered by 4 years ago

In the Badges API there is a third parameter for specifying the cursor. Basically when you make a request to return the player's 100 badges, it includes a key called nextPageCursor, which is a parameter that you'd include in your link to get the next page. By using a loop he meant keep sending requests with the cursor parameter included until there is no more next page.

0
and what should the third parameter be exactly? OX_X4 2 — 4y
Ad

Answer this question