Place Visits Help!

Problem

this is not a problem it’s more of a question and I don’t know where to post this forum but I was wondering, is there a way to see players place visits and added it to the leader stats if there is how so…

please don’t remove this from this category this was where my topic most fit

2 Likes

You would have to scrape their profile, or loop through every single game they’ve made. Either way, you’ll need a proxy.

This endpoint lets you get a user’s games:
https://games.roblox.com/docs#!/Games/get_v2_users_userId_games
While this endpoint gets you a Visits count from a game:
https://games.roblox.com/docs#!/Games/get_v1_games

7 Likes

@posatta
what code do I need to do that and what do you mean by a proxy because some games like Flex Your Roblox Account Age, they have a feature where you can not go in a certain place if your place visits are too low. and i do not know how but i am trying to find out :smile:

1 Like

Not anything too complicated.

Just do what posatta said,


local players = game:GetService("Players")
local HTTP = game:GetService("HttpService")
local Time_Cap = 35 -- 35 seconds max

local function OnAdded(player)
	print("welcome, ", player.Name)
	local id = player.UserId
	local endpoint, place_details = "https://games.rprxy.xyz/v2/users/"..id.."/games?accessFilter=Public&sortOrder=Asc&limit=25", "https://games.rprxy.xyz/v1/games?universeIds="
	local data, tries, completed = nil, 0, false
	
	local ids, visits = {}, {}
	
	ids[player.Name] = {}
	visits[player.Name] = 0
	
	
	coroutine.wrap(function()
		local started = os.time()
		while not completed do 
			if os.time() - started >= Time_Cap then print("aborting operation") -- can be eliminated with an 'and' above
				return
			 end
			wait(0.2)
		end
	end)()
	   	
	
	while not data and tries < 4 do 
		
	pcall(function()
		data = HTTP:GetAsync(endpoint)
	end)
		tries += 1
		wait(3)
	end
	
	if data then	
	data = HTTP:JSONDecode(data).data
		for _, value in pairs(data) do		
		    table.insert(ids[player.Name], value.id) print("inserted place id: ", value.id)
		  end
	   end
   
	local throttle = 0
	
	for _, id in pairs(ids[player.Name]) do
		    
		if throttle == 5 then wait(4) throttle = 0 end
		pcall(function()
			data = HTTP:GetAsync(place_details..id)
		end)
		
		if data then
			data = HTTP:JSONDecode(data).data[1]
		    visits[player.Name] += tonumber(data.visits) print("added visits: ", data.visits)	
		end
 	       throttle += 1
	end
	
	print("total visits: ", visits[player.Name])

end

players.PlayerAdded:Connect(OnAdded)

I didn’t take care about efficiency or anything, just wrote it as I saw the post before (also edited it significantly before posting).

I used a JSON viewer to better understand the format by directly visiting the link at game.roblox.com/v2/docs etc. , other than from the provided example response

Edit: This basically just retrieves the value for every player, creating a value under a leaderstat is too simple to be explained.

Create a new thread if you need assistance with that.

Edit2: Nevermind here’s the full code I hope you will try to at the very least, understand:

effortless leaderstats addition, that could've been achieved through searching for or creating a new thread

local players = game:GetService("Players")
local HTTP = game:GetService("HttpService")
local Time_Cap = 35 -- 35 seconds max

local function OnAdded(player)
	print("welcome, ", player.Name)
	local id = player.UserId
	local endpoint, place_details = "https://games.rprxy.xyz/v2/users/"..id.."/games?accessFilter=Public&sortOrder=Asc&limit=25", "https://games.rprxy.xyz/v1/games?universeIds="
	local data, tries, completed = nil, 0, false
    local lead = Instance.new("folder")
    lead.Name = "leaderstats"
    local val = Instance.new("IntValue")
    val.Name = "visits"
	local ids, visits = {}, {}
	
	ids[player.Name] = {}
	visits[player.Name] = 0
	
	
	coroutine.wrap(function()
		local started = os.time()
		while not completed do 
			if os.time() - started >= Time_Cap then print("aborting operation") -- can be eliminated with an 'and' above
				return
			 end
			wait(0.2)
		end
	end)()
	   	
	
	while not data and tries < 4 do 
		
	pcall(function()
		data = HTTP:GetAsync(endpoint)
	end)
		tries += 1
		wait(3)
	end
	
	if data then	
	data = HTTP:JSONDecode(data).data
		for _, value in pairs(data) do		
		    table.insert(ids[player.Name], value.id) print("inserted place id: ", value.id)
		  end
	   end
   
	local throttle = 0
	
	for _, id in pairs(ids[player.Name]) do
		    
		if throttle == 5 then wait(4) throttle = 0 end
		pcall(function()
			data = HTTP:GetAsync(place_details..id)
		end)
		
		if data then
			data = HTTP:JSONDecode(data).data[1]
		    visits[player.Name] += tonumber(data.visits) print("added visits: ", data.visits)	
		end
 	       throttle += 1
	end
	
	print("total visits: ", visits[player.Name])
    val.Value = visits[player.Name]
    val.Parent = lead
    lead.Parent = player
end

players.PlayerAdded:Connect(OnAdded)

Server-scripts should canonically be in ServerScriptService.

5 Likes

how would i be able to add this to a leaderstat?

1 Like