I have a menu, I want to show the thumbnails in a slideshow, how can I insert the thumbnails into a table, and then loop through them?
This is on a ImageLabel by the way
local http = game:GetService("HttpService")
local getAsync = http.GetAsync
local jsonDecode = http.JSONDecode
local gameThumbnailsUrl = "https://games.roproxy.com/v2/games/%s/media"
local function getGameThumbnails(gameId, thumbnails, maxTries)
gameId = gameId or game.GameId
thumbnails = thumbnails or {}
maxTries = maxTries or 5
if maxTries == 0 then return end
maxTries -= 1
local requestUrl = gameThumbnailsUrl:format(gameId)
local success, result = pcall(getAsync, http, requestUrl)
if success then
if result then
local success2, result2 = pcall(jsonDecode, http, result)
if success2 then
if result2 then
for _, thumbnailItem in ipairs(result2.data) do
table.insert(thumbnails, thumbnailItem.imageId)
end
return thumbnails
end
else
warn(result2)
task.wait()
getGameThumbnails(gameId, thumbnails, maxTries)
end
end
else
warn(result)
task.wait()
getGameThumbnails(gameId, thumbnails, maxTries)
end
end
local gameThumbnails = getGameThumbnails(2938572470)
print(#gameThumbnails) --4
for _, thumbnailId in ipairs(gameThumbnails) do
print(thumbnailId) --4 thumbnail IDs.
end
Here you go, I wrote this script which fetches the asset IDs of all thumbnails of a game.
Should I use the UniverseId or the placeId, and if I have to use the UniverseId, how would I get the it from the script?
You need to use a universe ID, as it stands the script automatically uses the game’s universe ID if the function is called with no arguments.
Well I mean like, getting the current universeId for the game during runtime.
gameId = gameId or game.GameId
That’s what this bit does, game.GameId
gets the current universe ID.
https://developer.roblox.com/en-us/api-reference/property/DataModel/GameId
I just tried it, my game has 3 thumbnails, but it returns 0. Any help?
8947071157
8947070963
8947071137
8947071090
These were outputted when inputting your game’s universe ID. Not sure where you went wrong.
Huh, that’s odd, its now outputting the info.
Wait, how can I add these to a folder through the server script?
I want to loop through them on the client.
You’ll need to perform this on the server and use a RemoteEvent/RemoteFunction instance to transmit the thumbnail IDs to the client.
Wait, can I use one RemoteEvent
for all of this?
(sorry if you read the previous reply and was about give me a solution.)
Yeah, the function returns a table of thumbnail IDs, you just need to transmit that table value to the client.