Sorry for my really late reply, but i made the code to properly get the total place visits and made it more accurate as previously only starter places were accounted for:
local httpService = game:GetService("HttpService")
local gamesApiCall = "https://games.roproxy.com/v2/users/%s/games?sortOrder=Asc&limit=50" --the api link, you can change the configurations or link.
local universeApiCall = "https://games.roproxy.com/v1/games?universeIds=%s" --universe info api link, this is used to get the game's total visits as previously only starter places were calculated
local function httpGetAsync(...) --let's make a function for this so we don't have to pcall every time
local response = nil
local args = ...
local success, msg = pcall(function()
response = httpService:GetAsync(args)
end)
if success and response then
return response
else
warn(msg)
end
end
local function fetchTotalPlaceVisits(playerId)
local totalPlaceVisits = 0
local requestLink = string.format(gamesApiCall, playerId)
local newRequestLink = nil
while true do
local response = httpGetAsync(newRequestLink or requestLink, false)
if response then
local tableResponse = httpService:JSONDecode(response)
for _, gameInfo in pairs(tableResponse.data) do
local universeResponse = httpGetAsync(string.format(universeApiCall, gameInfo.id), false)
if universeResponse then
local universeTableResponse = httpService:JSONDecode(universeResponse)
totalPlaceVisits += universeTableResponse.data[1].visits
else
warn("Unable to retrieve universe information, using place visits instead")
totalPlaceVisits += gameInfo.placeVisits
end
end
if tableResponse.nextPageCursor then
newRequestLink = requestLink .. "&cursor=" .. tableResponse.nextPageCursor
else
break
end
else
break
end
end
return totalPlaceVisits
end
print(fetchTotalPlaceVisits(85103695)) --YIELDS FOR ABOUT 1-10 SECONDS DEPENDING ON HOW MANY GAMES THE USER HAS.
This is not a very efficient way as multiple API calls are made but it is certainly accurate, this is the only way to do this as roblox does not give us a way to read the total visits, if roblox ever releases an API or any method in the future that allows you to read total place visits directly instead of having to calculate it like this i highly recommend you swap to that, but as for now you can use this.