Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
15

is there a function that can return the number of members a group has? [closed]

Asked by
nich17 95
9 years ago

i am simply curious to know if there is a function that can return the number of members that a group has and if so how would i use it??

1
This is a good question BSIncorporated 640 — 9y
0
thank you nich17 95 — 9y
0
Agreed. I did check ROBLOX's official group APIs when I looked at this question to see if I could find anything, but with no luck. Spongocardo 1991 — 9y
0
alright thanks anyway nich17 95 — 9y

Locked by HungryJaffer, User#5978, LegitimatlyMe, and BlackJPI

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
10
Answered by
Unclear 1776 Moderation Voter
9 years ago

There is probably some public API out there, but since I have no knowledge of web development and it seems you do not either, I will show you the way I would do it using only RBX.Lua.

When thinking of where I would find the size of a group on the website, I immediately thought of the group page. When you visit a group page on Roblox it begins with http://www.roblox.com/Groups/group.aspx?gid= followed by the group's id number.

Now that we know on what page what we are looking for would be displayed on, we just have to get the web page! Fortunately, ROBLOX's HttpService already has one for us: GetAsync! GetAsync can give us the HTML representation of the page that we request, which is a step closer to extracting the information we need.

Note: When you use GetAsync on a page on ROBLOX, be sure to use roproxy.tk or some other ROBLOX proxy instead of roblox.com. GetAsync cannot be used on ROBLOX's own pages!

Next, we need to process the HTML and find exactly what we are looking for. Since I have no knowledge of HTML, I just opened up the group webpage and looked for the number on Chrome. I used CTRL+F to find "Members:" in the huge mess of HTML, and I found the following:

<div id="MemberCount">Members: 8</div>

Since GetAsync gets us a string with the HTML in it, we just have to find that line! With my knowledge of string manipulation in Lua, I knew there was a function called match in the string library that I could use to match lines that are similar to the one above from a large amount of text. If html was a variable that pointed to the HTML source, then I would do something like:

local pattern = [[<div id="MemberCount">Members: %d+</div>]]
local line = html:match(pattern)

The above would get rid of the rest of the code and give me only the line that looks similar to the line above. We're not done yet, though! Notice that we still do not only have numbers. Fortunately, in this line there is only one possible number, which is the group size. We can use match again and search only for numbers using the string pattern %d+. I would then do something like this:

local pattern = [[<div id="MemberCount">Members: %d+</div>]]
local line = html:match(pattern)
local size = line:match("%d+")

Then we're done! Altogether, here is a function that will get the size of a group on ROBLOX.

function getGroupSize(groupId)
    local groupLink = "http://www.roproxy.tk/My/Groups.aspx?gid=" .. groupId
    local html = game:GetService("HttpService"):GetAsync(groupLink, true)
    local pattern = [[<div id="MemberCount">Members: %d+</div>]]
    local size = tonumber(html:match(pattern):match("%d+"))
    return size
end

-- Test with my development circle, Hanabi
-- http://www.roblox.com/My/Groups.aspx?gid=2578747
print(getGroupSize(2578747)) --> 8
1
wow MessorAdmin 598 — 9y
1
amazing HungryJaffer 1246 — 8y
Ad