I have a script which gets a player t shirts and puts them on buttons for other players to buy, how would I add into this script so that is also gets the players gamepasses, and displays them as buttons which can be purchased the same way the t shirts are displayed. Thanks.
local function FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
Cursor = Cursor or ""
return "https://catalog.roproxy.com/v1/search/items/details?Category=Clothing&Subcategory=ClassicTShirts&Limit=30&CreatorTargetId="..UserId.."&Cursor="..Cursor
end
local function TableConcat(TableA, TableB)
local TableC = {}
for i, v in ipairs(TableA) do
table.insert(TableC, v)
end
for i, v in ipairs(TableB) do
table.insert(TableC, v)
end
return TableC
end
local function GetUserGeneratedTShirts(UserId, Limit, Cursor)
local TShirts = {}
local Endpoint = FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
local Success, Result = pcall(function()
return Http:GetAsync(Endpoint)
end)
if not Success then
warn("Unable to get t-shirts from API: "..Result)
return TShirts
end
local Success2, Result2 = pcall(function()
return Http:JSONDecode(Result)
end)
if not Success2 then
warn("Unable to decode response from t-shirts API: "..Result2)
return TShirts
end
for _, TShirt in ipairs(Result2.data) do
table.insert(TShirts, TShirt.id)
end
if #TShirts >= Limit then
return TShirts
else
Cursor = Result2.nextPageCursor
if Cursor then
local MoreTShirts = GetUserGeneratedTShirts(UserId, Limit, Cursor)
return TableConcat(TShirts, MoreTShirts)
else
return TShirts
end
end
end
local userTShirts = GetUserGeneratedTShirts(winnerId, 10)
local num = (#userTShirts)
loser.PlayerGui.Donation.Frame.TextLabel.Text = "Donate to ".. winnerName
local table1 = {}
for i = num, 1, -1 do
local Asset = MarketPlaceService:GetProductInfo(userTShirts[i])
local assetPrice = Asset.PriceInRobux
local assetId = Asset.AssetId
if assetPrice == nil or assetId == nil then
print("Failure")
else
-- Create a new table for each item with the price and id
local item = {price = assetPrice, id = assetId}
-- Insert the item into the table
table.insert(table1, item)
end
-- Create a new table for each item with the price and id
end
table.sort(table1, function(a, b)
return a.price < b.price
end)
for i, item in ipairs(table1) do
if item then
local price = item.price or "default price"
local id = item.id or "unknown"
local newButton = workspace.DonateButton:Clone()
newButton.Name = "DonateButton"..i
local priceValue = Instance.new("IntValue", newButton)
priceValue.Name = "Price"
priceValue.Value = price
newButton.Text = price .. " R$"
local id = Instance.new("IntValue", newButton)
id.Value = item.id
newButton.Parent = loser.PlayerGui.Donation.Frame.itemsScroller
else
end
end