I’d like to get the amount of RAP every player has and then put it into the leaderboard. Would I be using MarketplaceService? This is a example of the values that I found - https://www.roblox.com/library/126295833/Catalog-Data
I am wondering how to do this.
I would check the API Reference (Roblox Engine API Reference | Documentation - Roblox Creator Hub) for MarketplaceService
just to get a wide reference of it, and then come back to us if you’ve come out empty.
I don’t think Roblox Lua allows this. You have multiple solutions to the problem here:
- You make a post on #platform-feedback:engine-features
- You read off an external plugin, the only way I could imagine going about this is HttpsService and an third-party browser plugin.
Doesn’t Trade Hangout have this? If it does, then it’s possible.
I expect the game uses the second solution I listed above.
What do you specifically mean by a third-party browser plugin?
Something like Roblox+ which allows you to view players’ RAP.
This is all I could find
-- refresh LimitedItems list every 2 minutes
-- fire remote every time LimitedItems updates
-- add rap tag over people's heads when they spawn
-- refresh UserAsset list on demand
function numerify(v)
if v < 1000 then
return ""
elseif v >= 1000000 then
return string.format("%.1fM+", v/1000000)
elseif v >= 10000 then
return string.format("%dk+", v/1000)
elseif v >= 1000 then
return string.format("%.1fk+", v/1000)
end
end
-- Modules
local LimitedItems = require(game.ServerStorage.Classes.LimitedItems)
local UserLimiteds = require(game.ServerStorage.Classes.UserLimiteds)
local UserLimitedTags = require(game.ServerStorage.Classes.UserLimitedTags)
-- Services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local RapDataStore = DataStoreService:GetOrderedDataStore("RecentAveragePrice")
local Settings = {
RefreshDebounce = 60 * 4;
}
There’s a lot more to this script, if you want me to send it.
Thanks, I see how this script is going.
And here is a another thing that looks like it will be relevant:
function addRapTag(player)
local userLimiteds = UserLimiteds.GetByUserID(player.userId)
local rap = userLimiteds:GetRAP()
--print("Adding rap tag")
local character = player.Character or player.CharacterAdded:wait()
local head = character:WaitForChild("Head")
local tag = Instance.new("BillboardGui")
tag.Name = "RapTag"
tag.Size = UDim2.new(2,0,1,0)
tag.StudsOffset = Vector3.new(0,3,0)
local label = Instance.new("TextLabel")
label.BackgroundTransparency = 1
label.Size = UDim2.new(1,0,1,0)
label.ClipsDescendants = true
label.TextColor3 = Color3.fromRGB(0, 144, 244)
label.TextStrokeColor3 = Color3.fromRGB(0, 45, 76)
label.TextScaled = true
label.TextStrokeTransparency = 0.5
label.Text = numerify(rap)
label.Font = Enum.Font.SourceSans
label.Parent = tag
tag.Parent = head
tag.Adornee = head
--print("Added rap tag")
end
local rapLimit = 100000 -- must have 100k to hang out in the lounge
function updateRapRanking(player,rap)
--print("Creating leaderstats for " .. player.Name)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Model")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
local rapValue = leaderstats:FindFirstChild("RAP")
if not rapValue then
rapValue = Instance.new("IntValue")
rapValue.Name = "RAP"
rapValue.Parent = leaderstats
end
rapValue.Value = rap
--print("Updating points for " .. player.Name)
local PointsService = game:GetService("PointsService")
--print("Updating RAP in data store")
RapDataStore:SetAsync(tostring(player.userId), rap)
local currentPoints = PointsService:GetGamePointBalance(player.userId)
local pointDifference = rap - currentPoints
if not (pointDifference == 0) then
PointsService:AwardPoints(player.userId,pointDifference)
end
end
function onPlayerAdded(player)
local userId = player.userId
--print("Getting UserLimiteds for user " .. userId)
local userLimiteds = UserLimiteds.GetByUserID(userId)
--print("Retrieved UserLimiteds")
local rap = userLimiteds:GetRAP()
updateRapRanking(player,rap)
if (rap >= rapLimit) then
local tag = Instance.new("StringValue")
tag.Name = "LoungeAccess"
tag.Parent = player
end
player.CharacterAdded:connect(function()
onCharacterAdded(player)
end)
onCharacterAdded(player)
end
function onCharacterAdded(player)
wait()
--print("CharacterAdded for " .. player.Name)
addRapTag(player)
end
function onPlayerRemoving(player)
if player then
--print("Player " .. player.Name .. " is leaving")
end
end
spawn(function()
for _,player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
end)
Players.PlayerAdded:connect(onPlayerAdded)
Players.PlayerRemoving:connect(onPlayerRemoving)
Little late but there is an API for this!
https://inventory.roblox.com/docs#!/Inventory/get_v1_users_userId_assets_collectibles
How would I apply this in game?
With a helpful proxy, such asrprxy.xyz
, you can access this in-game with HttpService’s GetAsync and Decode it into a Lua table via JSONDecode.
Here’s a simple example:
local HttpService = game:GetService("HttpService")
local UserId = 1 --// UserId of the person you want to find the RAP of
local URL = string.format("https://inventory.rprxy.xyz/v1/users/%d/assets/collectibles?sortOrder=Asc&limit=100", UserId)
local Data = HttpService:GetAsync(URL) --// Send a GET request to the proxy
local DecodedData = HttpService:JSONDecode(Data) --// Make the data into a valid Lua table
local TotalRAP = 0
for _, Item in ipairs(DecodedData.data) do --// Iterate through and add each item's RAP
TotalRAP = TotalRAP + Item.recentAveragePrice
end
I am having a bit of trouble creating the proxy…
I can get this to work -
https://inventory.roblox.com/v1/users/1/assets/collectibles?sortOrder=Asc&limit=10
But this does not work when I click on it. Will it work in-game?
Without a proxy, you cannot send requests to Roblox’s own domains in-game (blocked by Roblox themselves).
A hosted application could be used as well, where you’d send a GET to it and it’d send a GET to the API.
No, I just found out what I did wrong. Your link was right I was unaware of the ‘%d’ I am testing currently with my inventory.
Last question, how can I make
local UserId = 1
into where whenever a player joins their RAP gets set.
How do I also set the TotalRAP val into a int value?
This is what I got
local HttpService = game:GetService("HttpService")
--// UserId of the person you want to find the RAP of
game.Players.PlayerAdded:Connect(function(player)
local URL = string.format("https://inventory.rprxy.xyz/v1/users/%d/assets/collectibles?sortOrder=Asc&limit=100", UserId)
local UserId = player.UserId
local Data = HttpService:GetAsync(URL) --// Send a GET request to the proxy
local DecodedData = HttpService:JSONDecode(Data) --// Make the data into a valid Lua table
local TotalRAP = 0
for _, Item in ipairs(DecodedData.data) do --// Iterate through and add each item's RAP
TotalRAP = TotalRAP + Item.recentAveragePrice
end
local leaderstats1 = player.leaderstats1
local RAP = Instance.new("IntValue")
RAP.Name = "RAP"
RAP.Parent = leaderstats1
RAP.Value = TotalRAP
print(TotalRAP)
end)
I am also getting some output errors on Line 5
It is because you declared UserID after line 5 (when you are calling it)
Move UserId before URL and I would set the Variable name to “UserID” case specific, because UserId is a property of Player
Here’s a working Version of what you want:
local HttpService = game:GetService("HttpService")
game.Players.PlayerAdded:Connect(function(player)
local UserId = player.UserId
local URL = string.format("https://inventory.rprxy.xyz/v1/users/%d/assets/collectibles?sortOrder=Asc&limit=100",UserId)
local Data = HttpService:GetAsync(URL)
local DecodedData = HttpService:JSONDecode(Data)
local TotalRAP = 0
for _, Item in ipairs(DecodedData.data) do
TotalRAP = TotalRAP + Item.recentAveragePrice
end
local stats = Instance.new("Folder",player)
stats.Name = "leaderstats"
local RAP = Instance.new("IntValue",stats)
RAP.Name = "Rap"
RAP.Value = TotalRAP
end)