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

How to get the rap of players?

Asked by 3 years ago

I know there is such thing as AccountAge but I was wondering if there is something similar to this but with rap?

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder", player)
    stats.Name = "leaderstats"
    local rap = Instance.new("StringValue", stats)
    rap.Name = "Rap"
    local Rap = player.Rap -- Not real
    rap.Value = tostring(Rap)
end)

2 answers

Log in to vote
1
Answered by 3 years ago

You can write a function to get the RAP with Roblox endpoints (like Sparks said). You will have to use a proxy (such as rprxy.xyz) but it's not a big problem. Let's start one-by-one

local Website = "https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s"

Set the website to https://inventory.roblox.com/v1/users/{userId}/assets/collectibles and replace "roblox.com" with "rprxy.xyz". We also set the sortOrder to ascending and the limit to 100

local Website = "https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

Get HttpService and Players

function CalculateRAP(Player)
    local Cursor = ""
    local UserID = 80254 -- Player.UserId
    local Running = true
    local Data
    local JSONData
    local RAP = 0
    local StartTime = os.time()
    local EndTime
end

Define the function with variables. In this case, there is no cursor, UserID is Stickmasterluke's, His current RAP is 0, and the StartTime is now

local Website = "https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

function CalculateRAP(Player)
    local Cursor = ""
    local UserID = 80254 --Player.UserId
    local Running = true
    local Data
    local JSONData
    local RAP = 0
    local StartTime = os.time()
    local EndTime

    while Running do
        JSONData = HttpService:GetAsync(string.format(Website, UserID, Cursor))
        Data = HttpService:JSONDecode(JSONData)
    end
end

While the code is running, the JSON data is requested from https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s, whereas %u is replaced with the UserID and %s is replaced by Cursor

local Website = "https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

function CalculateRAP(Player)
    local Cursor = ""
    local UserID = 80254 --Player.UserId
    local Running = true
    local Data
    local JSONData
    local RAP = 0
    local StartTime = os.time()
    local EndTime

    while Running do
        JSONData = HttpService:GetAsync(string.format(Website, UserID, Cursor))
        Data = HttpService:JSONDecode(JSONData)
        for Index,Item in pairs(Data.data) do
            if Item.recentAveragePrice then
                print(string.format("Current RAP: %u. RAP of %s: %u.", RAP, Item.name, Item.recentAveragePrice))
                RAP = RAP + Item.recentAveragePrice
            else
                Running = false
            end
            wait()
        end
    end
end

Loops through all items in the page and sums up their RAP. Notice that this will get 100 items at maximum...

local Website = "https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

function CalculateRAP(Player)
    local Cursor = ""
    local UserID = 80254 --Player.UserId
    local Running = true
    local Data
    local JSONData
    local RAP = 0
    local StartTime = os.time()
    local EndTime

    while Running do
        JSONData = HttpService:GetAsync(string.format(Website, UserID, Cursor))
        Data = HttpService:JSONDecode(JSONData)
        for Index,Item in pairs(Data.data) do
            if Item.recentAveragePrice then
                print(string.format("Current RAP: %u. RAP of %s: %u.", RAP, Item.name, Item.recentAveragePrice))
                RAP = RAP + Item.recentAveragePrice
            else
                Running = false
            end
            wait()
        end
        if Data.nextPageCursor then
            Cursor = Data.nextPageCursor
            wait()
        else
            Running = false
        end
    end
end

... so we will need a page cursor! If the next page exists, flip to the next page. Otherwise, stop running.

And finally:

local Website = "https://inventory.rprxy.xyz/v1/users/%u/assets/collectibles?sortOrder=Asc&limit=100&cursor=%s"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

function CalculateRAP(Player)
    local Cursor = ""
    local UserID = 80254 --Player.UserId
    local Running = true
    local Data
    local JSONData
    local RAP = 0
    local StartTime = os.time()
    local EndTime

    while Running do
        JSONData = HttpService:GetAsync(string.format(Website, UserID, Cursor))
        Data = HttpService:JSONDecode(JSONData)
        for Index,Item in pairs(Data.data) do
            if Item.recentAveragePrice then
                print(string.format("Current RAP: %u. RAP of %s: %u.", RAP, Item.name, Item.recentAveragePrice))
                RAP = RAP + Item.recentAveragePrice
            else
                Running = false
            end
            wait()
        end
        if Data.nextPageCursor then
            Cursor = Data.nextPageCursor
            wait()
        else
            Running = false
        end
    end
    local EndTime = os.time()

    print(string.format("%s has %u RAP. That took %u seconds!", Player.Name, RAP, EndTime - StartTime))
end

Players.PlayerAdded:Connect(CalculateRAP)

Connect it to the event PlayerAdded and output how long it took.

0
you can use roblox's api website 3F1VE 257 — 3y
0
No you can't. It will filter User#30567 0 — 3y
Ad
Log in to vote
1
Answered by
Sparks 534 Moderation Voter
3 years ago

There is no way to do this without some kind of proxy server to handle web requests.

Roblox has an endpoint in the Inventory API that allows you to get a table of collectibles from a user. In each collectible entry in the table, there is a value called "recentAveragePrice;" you would have to add up the RAP of each item to get the total RAP of the user.

You cannot do this directly with HttpService as Roblox does not allow you to make requests to roblox.com. The point of the proxy server is to use HttpService to make a request to your site, which will then use the information about the user provided in the headers to make a request to the Inventory endpoint and return the final RAP to you.

Answer this question