I am trying to make a script which takes in a group ID, and searches all of its games and returns ones which return a certain phrase (in my case only public games include the phrase) and then print each of the games’ title, like count, favorite count, active players, and visits.
Code:
-- Constants
local groupId = 34471199
local baseUrl = "https://games.roproxy.com/v2/groups/" .. groupId .. "/games?accessFilter=1&limit=10&sortOrder=Asc"
local searchWord = "NovaSpark"
-- Services
local HttpService = game:GetService("HttpService")
-- Function to get data from the API
local function getData(url)
local options = {
Url = url,
Method = "GET",
}
local success, response = pcall(function()
return HttpService:RequestAsync(options)
end)
if success then
if response.StatusCode == 200 then
local successDecode, data = pcall(function()
return HttpService:JSONDecode(response.Body)
end)
if successDecode then
return data
else
warn("Failed to decode JSON response from URL: " .. url)
warn("Response Body: " .. response.Body)
return nil
end
else
warn("Failed to get data from URL: " .. url)
warn("Response Status: " .. tostring(response.StatusCode))
warn("Response Body: " .. tostring(response.Body))
return nil
end
else
warn("Request to URL failed: " .. url)
warn("Error: " .. tostring(response))
return nil
end
end
-- Function to fetch and filter games
local function fetchAndFilterGames()
local url = baseUrl
print("Fetching games from URL: " .. url) -- Logging the URL
local data = getData(url)
if data and data.errors then
warn("Error fetching data:")
for _, error in ipairs(data.errors) do
warn("Code: " .. error.code .. ", Message: " .. error.message)
end
return {}
elseif data and data.data then
local games = data.data
local filteredGames = {}
for _, game in ipairs(games) do
if game.description and string.find(game.description, searchWord) then
table.insert(filteredGames, game)
end
end
return filteredGames
else
warn("No game data found for the group or failed to fetch data")
return {}
end
end
-- Function to print game details
local function printGameDetails(game)
local placeId = game.PlaceId
local placeInfoUrl = "https://games.roproxy.com/v1/games?universeIds=" .. placeId
local placeData = getData(placeInfoUrl)
if placeData and placeData.data and placeData.data[1] then
local placeStats = placeData.data[1]
print("Title: " .. placeStats.name)
print("Number of Likes: " .. placeStats.totalUpVotes)
print("Number of Favourites: " .. placeStats.favoritedCount)
print("Number of Active Players: " .. placeStats.playing)
print("Visit Count: " .. placeStats.visits)
print("------")
else
warn("No data found for place ID: " .. placeId)
end
end
-- Main script execution
local function main()
local games = fetchAndFilterGames()
for _, game in ipairs(games) do
printGameDetails(game)
end
end
main()
And this is the error I get:
(Don’t judge the comic sans font)
Any and all help will be greatly appreciated… thank you!!