-
What do you want to achieve?
How can I check the list of groups in which the player is located and on the servers he owns it has taken visits from all games -
What solutions have you tried so far?
Roblox studio, youtube, itd…
To get the groups a user is in you should be able to use Group Service like this:
local gs = game:GetService("GroupService")
local groups = gs:GetGroupsAsync(plr.UserId) -- Get all groups as a table (Must have the player)
im a bit confused on what you mean there could you elaborate?
The idea is to check if the player is the owner of the group and if so, it checks the list of games on the group and takes the visits from them and adds them up
Well you should be able to loop through the groups table then use the roblox api with a proxy to communicate with it since roblox doesn’t let you directly communicate with it.
i threw this script together quickly but it seems to work
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local HttpService = game:GetService("HttpService")
local function calculateTotalPlaceVisits(gamesData)
local totalPlaceVisits = 0
for _, game in ipairs(gamesData) do
totalPlaceVisits = totalPlaceVisits + game.placeVisits
end
return totalPlaceVisits
end
Players.PlayerAdded:Connect(function(player) -- Or any event where player can be used
local success, groups = pcall(function()
return GroupService:GetGroupsAsync(player.UserId)
end)
if not success then
warn("Failed to fetch groups for player: " .. player.Name)
return
end
for _, group in ipairs(groups) do
if group.Rank == 255 then
print("Player owns group: " .. group.Name .. " (ID: " .. group.Id .. ")")
local endpoint = `https://games.roproxy.com/v2/groups/{group.Id}/gamesV2?accessFilter=2&limit=100`
local response = HttpService:JSONDecode(HttpService:GetAsync(endpoint))
local totalVisits = calculateTotalPlaceVisits(response.data)
print("Total Place Visits: " .. totalVisits)
end
end
end)
for example thats what would be printed if its looking at me
That’s probably an issue with how you’re accessing the function, unless it errors if you tried print(response.data)
?
It’s the function, if it was response.data
it’d throw an Index error.
Attempt to index nil with <PROPR>
response data gives me nil back
You have HTTP access in Studio enabled right?
Yes it is obvious
Try using pcall
s when you’re trying to fetch the data from the proxy.
local response, data;
pcall(function(): ()
response = HttpService:GetAsync(endpoint);
end);
--// Use response if it is not `nil`
if (response) then
--// Decode the JSON from the response
data = HttpService:JSONDecode(response);
else
print("Couldn't fetch player data.")
end;
Like I said before, use pcall
s (see prev reply)
The comment --// ...
(line 34) indicates that you’re supposed to move your response logic there.
Also make sure that GameCore.calculateTotalGroupPlaceVisits
is a valid function.
It is a private function (not visible/usable for anyone who requires the module). To make it a global function just add it to the module using .
--// Before
function calculateTotalGroupPlaceVisits(): ()
end;
--// After
function module.calculateTotalGroupPlaceVisits(): ()
end;
ERRATA:
- Fixed typo
- You aren’t decoding the response which was fetched from the proxy.
You are doing response.data
, which would be nil
as data is a property of the decoded json.
if (response) then
--// Decode the JSON from the response
data = HttpService:JSONDecode(response);
else
print("Couldn't fetch player data.")
end;
^^ this code was already there in my reply, I have no clue as to why you didn’t use it
You’re still using response.data
, use data.data
.