I am trying to make a billboard that shows catalog items. I have seen posts using the Roblox API to do this. I tried to do this on my own, but I have very little knowledge of HTTPService. Here’s the script:
local TOP30HATSBILLBOARD = workspace:WaitForChild("ShowcaseTop30Hats"):WaitForChild("Top30Hats")
local HTTP = game:GetService("HttpService")
local JSONDecode = HTTP.JSONDecode
local GET = HTTP.GetAsync
local url = "https://catalog.roproxy.com/v1/search/items/details?Category=3&MaxPrice=1000"
local function getTop30Hats()
local success,result = pcall(GET,HTTP,url)
if success and result and result.Success then
print("Success!")
print(result)
--local result2
local successdecode,resultDecode = pcall(JSONDecode,HTTP,result)
if successdecode and resultDecode then
for _,info in next,resultDecode.Data do
print("Successfully loaded information..")
for i = 1, #resultDecode do
local hatImage = Instance.new("ImageLabel",TOP30HATSBILLBOARD)
hatImage.Size = UDim2.new(0,225,0,200)
hatImage.Image = "rbxthumb://type=Asset&id=" .. info.productId
hatImage.BackgroundTransparency = 1
local hatNameAndPrice = Instance.new("TextLabel",hatImage)
hatNameAndPrice.Size = UDim2.new(0,200,0,50)
hatNameAndPrice.TextScaled = true
hatNameAndPrice.Position = UDim2.new(0,15,0,210)
hatNameAndPrice.BackgroundTransparency = 1
hatNameAndPrice.Font = Enum.Font
hatNameAndPrice.Font = Enum.Font.Roboto
hatNameAndPrice.FontFace.Bold = true
hatNameAndPrice.TextColor = BrickColor.Gray()
hatNameAndPrice.Text = info.name .. " $" .. info.price
print("Success!")
end
end
else
warn("Error happened decoding!")
end
else
warn("Error occured!")
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
getTop30Hats()
end)
end)
Any help is appreciated! Note: If the error is from the proxy itself, then give me a good proxy to use.
There’s a couple things I’ve noticed with the provided code.
The GET function is never being called, it should be GET(url)
The JSONDecode is not called correctly. It should be JSONDecode(HTTP, result.Body)
The for loop that creates the hatImage and hatNameAndPrice objs should be using #info instead of #resultDecode, since resultDecode is an obj that contains a Data array.
I’ve made changes that should work.
My Approach
local TOP30HATSBILLBOARD = workspace:WaitForChild("ShowcaseTop30Hats"):WaitForChild("Top30Hats")
local HTTP = game:GetService("HttpService")
local JSONDecode = HTTP.JSONDecode
local GET = HTTP.GetAsync
local url = "https://search.roblox.com/v1/catalog/items?category=3&maxPrice=1000&sortType=1&creatorTargetId=0&minPrice=0"
local function getTop30Hats()
local success, result = pcall(GET, HTTP, url)
if success and result.Success then
print("Success!")
local successDecode, resultDecode = pcall(JSONDecode, HTTP, result.Body)
if successDecode and resultDecode then
for _, info in ipairs(resultDecode.data) do
print("Successfully loaded information..")
local hatImage = Instance.new("ImageLabel", TOP30HATSBILLBOARD)
hatImage.Size = UDim2.new(0, 225, 0, 200)
hatImage.Image = "rbxthumb://type=Asset&id=" .. info.id .. "&w=420&h=420"
hatImage.BackgroundTransparency = 1
local hatNameAndPrice = Instance.new("TextLabel", hatImage)
hatNameAndPrice.Size = UDim2.new(0, 200, 0, 50)
hatNameAndPrice.TextScaled = true
hatNameAndPrice.Position = UDim2.new(0, 15, 0, 210)
hatNameAndPrice.BackgroundTransparency = 1
hatNameAndPrice.Font = Enum.Font.Roboto
hatNameAndPrice.FontSize = Enum.FontSize.Size24
hatNameAndPrice.FontWeight = Enum.FontWeight.Bold
hatNameAndPrice.TextColor3 = Color3.fromRGB(255, 255, 255)
hatNameAndPrice.Text = info.name .. " $" .. info.priceInRobux
print("Success!")
end
else
warn("Error happened decoding!")
end
else
warn("Error occurred!")
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
getTop30Hats()
end)
end)