How to tell if a user is in a group?

Hello, I’m trying to tell if a user is in a group

I already know about Player:IsInGroup(GroupId)

However that requires a player model and I want to do it based on

USERID not PLAYER MODEL

3 Likes

I’m assuming you mean that you want to check if people, not currently in the game, are in a group. I don’t think this is possible without using HTTPService.

1 Like

what about groupservice? group service doesnt require HTTP requests.

1 Like

Oh right, yes, that has a function GetGroupsAsync() that takes a userid.

GroupService.GetGroupsAsync

1 Like

how does this work ive been trying for over 2 months to get this.

It returns a list of tables containing information on all of the groups a given player is a member of.

can it get their role i.e 255 or 100 or just the group?

It seems like

local GroupService = game:GetService("GroupService")
local groups = GroupService:GetGroupsAsync(player.UserId)

print(groups) -- array of all groups and group info (such as image, members, name etc)

also no I am trying to check if they are in a group for my plugin. (in case they make a gamepass that is owned by a group I need to check if they are actually in that group so they dont get scammed by third party sales)

Loop through the groups they’re in and if it matches a name then bingo.

Looking for a name is too dynamic of a criteria, as the Group’s name can change. Check for the Group’s ID, and if it matches the ID of the group you require, then return true. I’m pretty sure the tables also contains the data for what rank the User has on the group as well, so if you’re looking for a specific Role Name or Role Priority you can check for that as well.

… ik its off topic and ill delete the post afterward but can someone answer my question… please

local function userIsInGroup(userid: number, groupId: number)
   local groups = GroupService:GetGroupsAsync(userid) -- get the user's groups
   for _, group in groups do -- loop through their groups
      if group.Id == groupId then -- check the group id
          return true -- user is in group
      end
   end

   return false -- user isn't in group
end
2 Likes

Depends on what he wants to check against.

its checking if the group is the same group that created the plugin.

I get the group from

game:GetService("MarketPlaceService"):GetProductInfo(assetId)

I only check if they are in the group if the creator of the gamepass is a group and not a player. If its a player then i check if that player is equal to the developer using the plugins userid.

Yes, the method returns the user’s rank.

3 Likes

Sure, he could check for the name, it’s just not practical long term, especially when it’s a changeable attribute.

If you’re using that to get the group then it’s fine to check against the name.

ok, thanks ill test it out, if this works i can remove like 100 lines of script in another script
lol