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.