I’m currently working on a project where I’m building a “wall of random images.” The idea is to randomly pull images from a large dataset and display them on a page. However, I’ve encountered an issue where some of these images aren’t public domain, leading to them appearing invisible or not loading at all.
To avoid this, I need a way to programmatically check if an image is public domain before trying to display it. I wanted to share my approach so far and get some feedback or suggestions on improving this process.
My current code:
task.spawn(function()
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
for i = 72,0,-1 do
local image = game.Players.LocalPlayer.PlayerGui.iame:Clone()
local success = false
local id = nil
local function call()
task.spawn(function()
pcall(function()
id = math.random(100000,100000000)
print("checked", id)
local place = game.MarketplaceService:GetProductInfo(id)
if place.AssetTypeId==1 then success = true print(place.Name) end
end)
end)
end
repeat wait() call() until success
if success then
print("got valid id")
if success then
image.ImageLabel.Image = "rbxassetid://"..id
end
image.Parent = gui
end
wait()
end
end)
Video as well. The output is each id it checks. the spaces in-between the images is the private ones(I have also just learned that there are tshirts in the mix, no idea why.) that I want to filter out.
Scratch that, its just not filtering to images
Any help would be appreciated, thanks for reading.
I ended up getting it to cover the screen and do it fast. I decided to do a mix of randomly generated ones and picked ones, ended up working well. (Excluding the fact i accidentally picked 200 pictures of the same face just slightly different lol.)
task.spawn(function()
for i = 72,0,-1 do
local choice = math.random(1,3)
if choice == 1 then
local image = game.Players.LocalPlayer.PlayerGui.iame:Clone()
local success = false
local id = nil
local typ = nil
local function call()
task.spawn(function()
pcall(function()
local checkid = math.random(5000000,100000000)
local asset = game.MarketplaceService:GetProductInfo(checkid,Enum.InfoType.Asset)
if asset.AssetTypeId == 1 or asset.AssetTypeId == 13 and asset.IsForSale==true then
success = true
typ = asset.AssetTypeId
id = checkid
end
end)
end)
end
repeat wait() call() until success
if success then
local asset = game.MarketplaceService:GetProductInfo(id,Enum.InfoType.Asset)
if asset.AssetTypeId == 1 or asset.AssetTypeId == 13 and asset.IsForSale==true then
image.ImageLabel.Image = "rbxassetid://"..id
image.Name = typ.." #".. i
image.Parent = gui
print("Picked random image:",asset.Name,"as #"..i)
end
end
else
local image = game.Players.LocalPlayer.PlayerGui.iame:Clone()
local picked = math.random(0,#pictureDB)
image.ImageLabel.Image = "rbxassetid://".. pictureDB[picked].Value
image.Name = "Pre-Generated #".. i
image.Parent = gui
print("picked random image #"..picked)
end
wait()
end
print("FULLY LOADED!!!")
end)
If it works then it works.
I would’ve recommended to use the Roblox Catalog API External Catalog Queries | Documentation - Roblox Creator Hub to get images (and spam random letters in the search query, because Roblox has introduced an algorithm that also tries to get assets with similar names to the search query) to guarantee a real and random image that isn’t cherrypicked.