I’m trying to get group info in Roblox, but the member count isn’t coming through “Owner User Is working”. Here’s the script I’m using:
groupInfoRequest.OnServerEvent:Connect(function(Player, groupID)
print("Received request for group ID:", groupID)
local groupInfo = game:GetService("GroupService"):GetGroupInfoAsync(groupID)
if groupInfo then
local memberCount = groupInfo.MemberCount or "N/A"
local groupData = {
Owner = groupInfo.Owner.Name,
MemberCount = memberCount
}
groupInfoRequest:FireClient(Player, true, groupData)
print("Group Data:", groupData.Owner, groupData.MemberCount)
else
print("Failed to retrieve group info.")
groupInfoRequest:FireClient(Player, false, nil)
end
end)
Can anyone help me figure out why the member count isn’t showing up?
I am looking at the documentation for GroupService and I am not seeing anything in the table here that would lead me to believe that groupInfo.MemberCount is a method that exists. It seems that you are trying to reference something which is not part of the table returned by calling :GetGroupInfoAsync().
Check out these threads for more information on how you can get this information using HttpService!
There is a roblox API that holds detailed information about groups like the member count. So we will need to access it using HTTP service
local HttpService = game:GetService("HttpService")
groupInfoRequest.OnServerEvent:Connect(function(Player, groupID)
print("Received request for group ID:", groupID)
local url = "https://groups.roblox.com/v1/groups/" .. groupID
local membercount
local success, response = pcall(function()
return HttpService:GetAsync(url)
end)
if success then
local data = HttpService:JSONDecode(response)
membercount = data.memberCount
else
warn("Failed to get group information.")
end
end)
if memberCount then
print("The group has " .. memberCount .. " members.")
else
print("Failed to retrieve the member count.")
end
Hello! I am the OP of the second resource you linked! Thank you for making me aware that this was still posted, I have updated the comment to reflect it no longer works and update some old bad coding practices. The code itself works fine, but the proxy no longer exists. There’s a lot of other proxies @kvautme could use and could just drop in as a replacement to the one I used 4 years ago.
Still waiting for Roblox to just have an official API usable in-game.