#Player roles In Group

1 messages · Page 1 of 1 (latest)

round sparrow
#

I've been trying to find a way (with no success so far) to collect all roles from a player in a certain group.

player:GetRankInGroup(GROUP_ID) will obviously only return 1 int value of the highest rank the member has in that group
GroupService:GetGroupInfoAsync(GROUP_ID) only checks the group info, no checks about the members
GroupService:GetRolesInGroupAsync(GROUP_ID) doesn't even exist in code yet cuz I tried it and it threw an error that it doesn't recognize this call. Its not even in beta features

I was thinking about trying to call a http jsondecode request but I don't have any apis to do that nor do I know how to make one
If I could make one, the idea would be that it'd request the external code to go to my roblox group, go through base member rank and list all userids/usernames in a table and then go through each role and if the code finds a member there then add that role to the table under that member's name and lastly return it all to the code in-game in a table

vital cape
#

check if the api's you listed return multiple args, they may have changed it

round sparrow
#

okay

#

i checked by requesting and printing every listed get in the message above and all of them had only 1 args except for the getgroupinfoasync which only had the group name, description, id, owner, emblem etc. No roles tho

languid bone
#

I think I figured out how to do what you were trying to do. It took me awhile because I got stuck on this but finally got it figured out! I've linked a video above on how to do it with the instructions provided below :)
Sorry if I gave bad instructions sob2

Notes

This only works for published games.
THE API KEY IS REQUIRED OR THIS WON'T WORK.
Yes, you can use HttpService for this, Roblox allows it for this instance.

Steps

  1. First you want to go the https://create.roblox.com. Then, select 'All Tools' and then select 'API Keys'. LINK: https://create.roblox.com/dashboard/credentials
  2. You want to create an API Key called 'Groups_API'.
  3. For 'Access Permissions' you want to set the API System to 'Groups', NOT 'Legacy Groups' or 'Group Forums'. After that, for the permissions, make sure you have read selected. You can also add write if you want, but it isn't needed in this situation.
  4. Then, press 'Save & Generate Key'. Once you created the API Key, a long line of text should appear with a button next to the right called 'Copy Key to Clipboard'. Press it.
  5. Now, on the creator dashboard page, find the game that you're trying to get the users roles in. Once your on the games dashboard page, under configure, select 'Secrets'.
  6. Create a secret, I'd recommend setting the name to 'Groups_API'. In the secret field, paste your API Key there, then click 'Create'.
  7. Open your game in studio. In the top left, navigate to File then press Experience Settings. Go to the security tab and make sure 'Allow HTTP Requests' is enabled as this is required to use HttpService.
  8. Under that settings, you should see something that says 'Local Secrets', this is required if you wanna test this in studio.
  9. Click Create and a new line under 'Local Secrets' should appear. It should say something like '(new secret 1)'. Click the 3 dots on the far right of it and do the same steps you did for steps 6 and 7.
  10. Lastly, create a script somewhere in your game where it can run at and paste the reference code below. (This code was rushed and only prints the role names so feel free to modify the code below.)
--// Service
local HttpService = game:GetService("HttpService")

--// Values
local GroupId = 14654842
local URL = "https://apis.roblox.com/cloud/v2/groups/"..GroupId.."/"
local API_Key = HttpService:GetSecret("Groups_API")

--// Functions
function GetRoleName(RoleId)
    assert(typeof(RoleId) == "number", "RoleId must be a number.")

    local Response = HttpService:RequestAsync({
        Url = URL.."roles/"..RoleId,
        Method = "GET",
        Headers = {
            ['x-api-key'] = API_Key
        }
    })
    if not Response.Success then return end

    local Data = HttpService:JSONDecode(Response.Body)
    return Data.displayName
end

function GetUsersRoles(UserId)
    assert(typeof(UserId) == "number", "UserId must be a number.")

    local GrabbedRoles = {}

    local Response = HttpService:RequestAsync({
        Url = URL.."memberships?maxPageSize=100&filter=user == 'users/"..UserId.."'",
        Method = "GET",
        Headers = {
            ['x-api-key'] = API_Key
        }
    })
    if not Response.Success then return end

    local Data = HttpService:JSONDecode(Response.Body)
    local Info = Data.groupMemberships[1]

    for _, role in pairs(Info.roles) do
        local RoleId = tonumber(string.match(role, "roles/(%d+)"))
        local RoleName = GetRoleName(RoleId)

        table.insert(GrabbedRoles, RoleName)
    end

    return GrabbedRoles
end

--// Stuff
local AllRoles = GetUsersRoles(274200990)
print(AllRoles)

Change the GroupId variable to your Groups ID and then change the UserId on the line with local AllRoles = GetUsersRoles(274200990) to the players id that you're trying to get the roles from.

languid bone
round sparrow
#

And this works? How? Does the api have special built in code when giving permission to groups?

#

Because the code is decoding the generated json api but wheres the code that it decodes?

#

Im not talking about the secret key but maybe the code is in fact in that secret key

languid bone
# round sparrow And this works? How? Does the api have special built in code when giving permiss...

Ye, it works. The secret key is not the code. I am pretty sure that the API Key is just for some type of authentication and permission control making sure that you can run that request on your group because you can also ban members, remove, and give members roles using the API. Whenever you send a request to Roblox's API service, it'll send the data back as a JSON string, and when you decode it, all it does is just turn the data from a JSON string into a Luau table.

round sparrow
#

I see, thanks!

languid bone
#

np!