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

Is it possible to check if a user is in a group, from their User Id alone?

Asked by
ExcelUp 24
6 years ago

Is it possible to check if a user is in a group, from their User Id alone?

I'll give my User Id '19497313' in the example below.

I've tried:

if 19497313:IsInGroup(4172264) then
    print("User is in group.")
end

But it doesn't seem to work, as I'd imagine that the 'IsInGroup' function only works with strings, not integers.

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

Player:IsInGroup() operates on instances (a form of userdata), not strings or integers. Instead, you'd want to use GroupService:GetGroupsAsync() like so:

local Services = {
    Group = game:GetService("GroupService")
}

local TargetUserId = 1
local TargetGroupId = 1

local UserGroups = Services.Group:GetGroupsAsync(TargetUserId)

for Index = 1, #UserGroups do
    local GroupData = UserGroups[Index]

    if TargetGroupId == GroupData.Id then
        print("Player with the target user ID is in the group!")
        break
    end
end

The Wiki API documentation for this method can be found here.

0
And what if I wanted to find a user's rank or role in a specific group from their User Id? ExcelUp 24 — 6y
1
You'd access GroupData.Rank and GroupData.Role in my example. Avigant 2374 — 6y
Ad

Answer this question