Hello Fellow Developers, I wanted to ask how I would go about making a system that counts a player total visits. I have looked through the API documentation from Roblox and there is no API to get the players visits. I have also looked through a few dev forum posts about this and I can’t find the solution. I hope you guys can help me figure out how to do this.
Just use the :GetPlayers method on Players Service, which returns a table of all player instances and then the length of that table using the # operator is your number of players in the server.
I don’t know much of this but you can try setting up a Proxy to Roblox’s API servers to access their API and get their place visits via HTML formatting. Search up how to set-up proxy’s
You can get all games from an user and calculate their visits from there like so:
local httpService = game:GetService("HttpService")
local function fetchTotalVisits(playerId)
local requestLink = "https://games.roproxy.com/v2/users/" ..playerId.."/games"
local response = httpService:GetAsync(requestLink)
local totalPlaceVisits = 0
local tableResponse = httpService:JSONDecode(response)
for _, gameInfo in pairs(tableResponse.data) do
totalPlaceVisits += gameInfo.placeVisits
end
return totalPlaceVisits
end
print(fetchTotalVisits(85103695))
Private games may not accounted for, but i think this is your best bet, atleast until roblox releases a way to get a player’s total visits from their profile.
Is there an alternative to this that would also account private games? I heard web scraping could be helpful for this but I have no clue on how to do it.
Figured it out, i was wrong, the games api does actually get all games it’s just that by default the limit is 10
Old:
local requestLink = "https://games.roproxy.com/v2/users/" ..playerId.."/games
Fixed:
local requestLink = "https://games.roproxy.com/v2/users/" ..playerId.."/games?sortOrder=Asc&limit=50" --Sets the limit to the max possible which is 50
Now it prints the correct amount of visits
Final Code:
local httpService = game:GetService("HttpService")
local function fetchTotalVisits(playerId)
local requestLink = "https://games.roproxy.com/v2/users/" ..playerId.."/games?sortOrder=Asc&limit=50"
local response = httpService:GetAsync(requestLink)
local totalPlaceVisits = 0
local tableResponse = httpService:JSONDecode(response)
for _, gameInfo in pairs(tableResponse.data) do
totalPlaceVisits += gameInfo.placeVisits
end
return totalPlaceVisits
end
print(fetchTotalVisits(85103695)) --> Prints user's total visits
I’m sorry but i do not know what is or how to web scrape, maybe even @Rdite could help you further or say how he did it but i’m fairly certain this is how he checks.
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.