How to see if someone is in a group or not via script

I have a textbox and whenever you enter in a Roblox username is fetches the username (so like if u type ‘thINKINGAiinight’ it will autocorrect to ‘ThinkingAIINight’), and the users Headshot image, but I was wondering how I could also get the rank of the user if their in my group or not.

Here’s a snip of my code.

local function OnFocusLost(EnterKeyPressed, InputThatCausedFocusLost)
	if EnterKeyPressed then
		local TextBoxText = TextBox.Text
		local EnteredNamesUserID = GetUserIDFromName(TextBoxText)
		local EnteredName = Players:GetNameFromUserIdAsync(EnteredNamesUserID)
		--local PlayerIsInGroup = EnteredNamesUserID:IsInGroup(GameDataModule.GroupID)
		TextBox.Text = ""
		Image.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..EnteredNamesUserID.."&width=420&height=420&format=png"
		PlayerName.Text = "Activity log for "..EnteredName
		--if PlayerIsInGroup then
			--PlayerRank.Text = EnteredNamesUserID:GetRoleInGroup(GameDataModule.GroupID)
		--else
			--PlayerRank.Text = "Customer"
		--end
		EditClose()
	end
end

TextBox.FocusLost:Connect(OnFocusLost)
local gs = game:GetService("GroupService")

local function OnFocusLost(EnterKeyPressed, InputThatCausedFocusLost)
	if EnterKeyPressed then
		local TextBoxText = TextBox.Text
		local EnteredNamesUserID = GetUserIDFromName(TextBoxText)
		local EnteredName = Players:GetNameFromUserIdAsync(EnteredNamesUserID)
		TextBox.Text = ""
		Image.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..EnteredNamesUserID.."&width=420&height=420&format=png"
		PlayerName.Text = "Activity log for "..EnteredName
		local group
		
		for i,v in pairs(gs:GetGroupsAsync(EnteredNamesUserID))
			if v.Id == GameDataModule.GroupID then group = v break end
		end
		
		if group then
			PlayerRank.Text = group.Role
		else
			PlayerRank.Text = "Customer"
		end
		
		EditClose()
	end
end

TextBox.FocusLost:Connect(OnFocusLost)
1 Like