Hello, i’m trying to make a script that gets the Roblox Games API, and prints in the console the place visits and favorited count, but all i get in the console is this: Visits: [object Undefined]. Favorites: [object Undefined].
(Note that there’s no errors after printing this)
Here’s the script:
const APILink = "https://games.roblox.com/v1/games?universeIds=2736413683"
const fetch = require('node-fetch');
function getVisits() {
let status;
fetch(APILink)
.then((res) => {
status = res.status;
return res.json()
})
.then((jsonData) => {
return jsonData.visits;
})
.catch((err) => {
console.error(err);
});
}
function getFavorites() {
let status;
fetch(APILink)
.then((res) => {
status = res.status;
return res.json()
})
.then((jsonData) => {
return jsonData.favoritedCount;
})
.catch((err) => {
console.error(err);
});
}
console.log("Visits: " + toString(getVisits()) + ". Favorites: " + toString(getFavorites()) + ".")
I searched everywhere on how could i fix this, but didn’t find anything, so how can i fix this?