Simple way to get a player's RAP

I’m making a leaderboard that displays a player’s RAP, but I have literally no idea. How do I do this

Leaderboard:

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local RAP = Instance.new("NumberValue")
    RAP.Name = "RAP"
    RAP.Value = 0
    RAP.Parent = Leaderstats
end)

This devforum post should help:

HTTP 503 (Service Unavailable)

local httpService = game:GetService("HttpService")

local function GetTotalRAP(userId)
	local success, msg = pcall(function()
		local total = 0

		local function CollectRAP(cursor)
			local url = "https://inventory.rprxy.xyz/v1/users/" .. userId .. "/assets/collectibles?sortOrder=Asc&limit=100"

			if cursor then
				url = url .. "&cursor=" .. cursor
			end

			local data = httpService:GetAsync(url)
			data = httpService:JSONDecode(data)

			for i = 1, #data["data"] do
				pcall(function()
					total = total + data["data"][i]["recentAveragePrice"]
				end)
			end

			if data["nextPageCursor"] then
				CollectRAP(data["nextPageCursor"])
			end
		end

		CollectRAP()

		return total
	end)

	if not success then
		warn(msg)
	else
		return msg
	end
end

print(GetTotalRAP(game.Players:GetUserIdFromNameAsync("ASTROCPF")))

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local RAP = Instance.new("NumberValue")
    RAP.Name = "RAP"
    RAP.Value = 0
    RAP.Parent = Leaderstats
end)

i get this error message

Do you have HTTP requests enabled in Game settings? If not, enable it
also rprxy.xyz is gone, so replace the link with roproxy.com

local url = "https://inventory.roproxy.com/v1/users/" .. userId .. "/assets/collectibles?sortOrder=Asc&limit=100"

it is enabled.

1 Like

As I said, rprxy.xyz is gone, so replace the link with roproxy.com

local url = "https://inventory.roproxy.com/v1/users/" .. userId .. "/assets/collectibles?sortOr

whats roproxy? i typed it in and it goes to roblox.com

It’s a roblox proxy…

1 Like

yo thanks it worked! ur a big w

2 Likes

When doing web requests always have in mind that they can fail at any given time. To combat this you can retry a request if it fails.

local httpService = game:GetService("HttpService")
local players = game:GetService("Players")
local maxRetries = 50

local function CollectRAP(userId)
	local total = 0
	local cursor = nil

	while true do
		local url = "https://inventory.roproxy.com/v1/users/" .. userId .. "/assets/collectibles?sortOrder=Asc&limit=100"
		if cursor then
			url = url .. "&cursor=" .. cursor
		end

		local data, success = nil, false
		for i = 1, maxRetries do -- retry
			data = httpService:GetAsync(url)
			success = pcall(function() data = httpService:JSONDecode(data) end)
			if success then break end
			wait(1) -- wait 1 second before retrying
		end

		if not success then
			error("Failed to retrieve data after" .. tostring(maxRetries) .. "attempts for player " .. players:GetNameFromUserIdAsync(userId))
		end

		for i, assetData in ipairs(data.data) do
			total = total + (assetData.recentAveragePrice or 0)
		end

		if not data.nextPageCursor then
			break
		end

		cursor = data.nextPageCursor
	end

	return total
end

local function GetTotalRAP(userId)
	if type(userId) ~= "number" then
		error("Invalid user ID for GetTotalRAP")
	end

	local success, total = pcall(CollectRAP, userId)
	if not success then
		warn("Failed to retrieve RAP for player " .. players:GetNameFromUserIdAsync(userId) .. ": " .. total)
		return nil
	end

	return total
end



players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	local RAP = Instance.new("NumberValue")
	RAP.Name = "RAP"
	RAP.Value = GetTotalRAP(Player.UserId)
	RAP.Parent = Leaderstats
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.