Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

2 comments

0

And what if I wanted to find a user's rank or role in a specific group from their User Id?

1

You'd access GroupData.Rank and GroupData.Role in my example.

This discussion is preserved as it was. New answers, comments, and votes are closed.