How do I use GetRankInGroup(Group ID) with a table?

I have a script that prints out a whole group in a table. As shown below:

print("Group name: Nighthawk Reaper Battalion")

local HttpService = game:GetService("HttpService")

local groupId = "4734688" --7581138



local URL = "https://groups.rprxy.xyz/v1/groups/" .. groupId .. "/users?sortOrder=Asc&limit=100"

local gottenPlayers = {}

local data
local response
local nextPage

local function getData()
	if nextPage then
		local s = pcall(function ()
			response = HttpService:GetAsync(URL .. "&cursor=" .. nextPage)
			data = HttpService:JSONDecode(response)
		end)
		return s
	else
		local s = pcall(function ()
			response = HttpService:GetAsync(URL)
			data = HttpService:JSONDecode(response)
		end)
		return s
	end
end

while wait() do
	if getData() then
		local users = data["data"]
		nextPage = data["nextPageCursor"]
		print("Requesting NRB Info")
		for i,v in ipairs(users) do
			local username = v["user"]["username"]
			local userid = v["user"]["userId"]
			table.insert(gottenPlayers, {username = username, userid = userid })
		end
		if not nextPage then
			break
		end
	else
		print("Something went wrong")
		break
	end
end

print(gottenPlayers)

The result is printed in this format:

 20:16:08.194   ▼ table: 0x9ced5db30c230f2c = {
                    [1] =  ▼ table: 0x481416ee064c96bc = {
                       ["userid"] = 8088440,
                       ["username"] = "Cryptonox"
                    },

What I need help with is how to use GetRankInGroup(Group ID) with the user id in the table to see if they have a rank in another group and print a message if they are.

not sure if i understand you correctly.
but basicly wat you want is a table of all the groups a player is part of?

What I want is to go through each ID in the table to see if any are in a specific group. Using GetRankInGroup(Group ID) as apparently that is the easiest way.

GetRankInGroup requires a Player instance (see: Player | Roblox Creator Documentation). You won’t be able to use a user id for this function.

What you would have to do instead is hit the Group API endpoint for getting a user’s group roles. Please see the following documentation: https://groups.roblox.com/docs#!/Groups/get_v2_users_userId_groups_roles

You would then need to loop through the response, checking the group id and if it is equal to the group id you’re looking for. Please note however with a dataset potentially as large as a whole entire group which I believe you’re wanting to run through, you’re likely to hit rate limits.

1 Like

getrank in group is a function of player.
but if i understand corretly the player you want to check might not be in game
and it is only one other group you want to check

a posible solution is to get a simulair table of that other group (and see if the Id pops up in both)

damit clan beat me to it

1 Like

I can do that but the other group is a problem as it has 144k members and that means around 1400 requests. which caps it.

And yes. That is true.

here i advice GetGroupsAsync.
this prints a table of all the groups a player is a part of. without the player having to be in game
then you can check if the other group is in that table

1 Like

Can I use that to see if a player is in another group without being in the game?

yes , it is a function of groupservice. not player
all you need is an playerid

How would I use this with a table? Because I really don’t know. Or will the ID in that not work?

I would suggest looking into the docs to understand how to iterate through tables. Please see: Tables | Roblox Creator Documentation

For what you’re asking:

local GroupService = game:GetService("GroupService")

for _, player in pairs(gottenPlayers) do
    local playerGroups = GroupService:GetGroupsAsync(player.userid)
end

player in this for loop will be each individual object for each player within your gottenPlayers table, your object looking something like this: {userid = 1, username = 'Foo'}

playerGroups will return an object containing some information about the group, namely the group id which you’re after.

2 Likes