How to calculate total rap a player has

I want to know how to make something like in Trade Hangout where it shows the total amount of rap a player has. But, in order to do this, I learned I had to use This Roblox Api in order to do so. I have no clue about how to incorporate Api into my roblox game. How should I script this? Here is my script now, but it doesn’t show rap;

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

	local RAP = Instance.new("IntValue",stats)
	RAP.Name = "Total RAP"
	RAP.Value = "?"
end)	
5 Likes

You can’t use the API endpoints on Roblox using HTTPService, the only way around it is by having a 3rd party web host retrieve the data.

Yes:

  1. Send a GET request to your own web server to get a player’s RAP.
  2. The web server will send a GET request to the Roblox API to collect the data and return it.

No:

  1. Send a GET request to the Roblox API to collect the data and return it.
1 Like

What web server should I use?

30 char

1 Like

You can use any, it’s more of a personal choice based on needs and experience. I use FastComet.

1 Like

Alright, thanks! I think this will work!

You can access the Roblox APIs through rprxy.xyz. This script gets the total RAP of a player through their user id, made for you. :slight_smile:

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("ForegoingTyler12943"))) -- Example

Let me know of any issues.

6 Likes

Thanks so much for this script! It works nicely by printing out the amount of rap I have, but what if I wanted the amount of player’s rap to be displayed in a screengui? How would I have to modify this script to make it work?

Sure, you can set up a simple system where a RemoteFunction is invoked from a LocalScript and the RAP for a player is returned from the server which can be used by the same LocalScript to edit a TextLabel. We do this simply because you can’t use HttpService on the client or else your IP can be stolen.

So what you would do is put this function inside the server script and call it whenever the client requests the RAP of a player.

1 Like

Hey! Just wondering… How and where did you get “https://inventory.rprxy.xyz/v1/users/” … userId … “/assets/collectibles?sortOrder=Asc&limit=100”. Also what is the parantheses defined as “cursor” meant to be?

Sorry for the late reply. Unfortunately rprxy.xyz was shut down by the owner. It was basically an alternative url that allowed you to sent HTTP requests to the Roblox web api as you aren’t allowed to directly do that on Roblox games. There are probably new alternatives that you may use now or maybe Roblox now allows you to call their web apis. I don’t know, it has been a while. Here’s where I got it: Inventory Api. ‘cursor’ is important because in a request you can only request up to 100 items owned by the user. If you want to go to the next ‘page’, you include a cursor that is supplied with the last request. This is automatically handled in the script that I wrote. It keeps loading their owned items until it reaches the end.