Clan System with support of Communities (Groups)

Here is my basic script
i will be referring Communities as groups fyi

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		-- Wait for the character to load
		local character = player.Character
		local clone = NameTag:Clone()
		clone.Parent = character.Head

		local TopText = clone.Frame.TopText
		local MiddleText = clone.Frame.MiddleText
		local BottomText = clone.Frame.BottomText

		-- Set player name
		TopText.Text = "@" .. player.Name

		-- Set team name and color
		if player.Team then
			MiddleText.Text = "["..player.Team.Name.."]"
			MiddleText.TextColor3 = player.TeamColor.Color
		else
			MiddleText.Text = "No Team"
			MiddleText.TextColor3 = Color3.new(1, 1, 1) -- Default white color
		end

		-- Check clan membership
		local clanName = "No Clan" -- Default text
		local clanId = 9850319 -- Replace with your group's ID

		-- Initialize rank to avoid errors
		local rank = "No Role"

		-- Check if the player is in the group
		if player:IsInGroup(clanId) then
			local groupInfo = GroupService:GetGroupInfoAsync(clanId)
			clanName = groupInfo.Name -- Set clan name from group info

			-- Get the player's role (rank name) in the group
			rank = player:GetRoleInGroup(clanId) -- This returns the rank as a string
		end

		-- Set the clan name and rank in the BottomText
		BottomText.Text = clanName .. "'s " .. rank
		BottomText.TextColor = BrickColor.new("Maroon")
       end)
end)

I want to change the color and name of their clan from input or a system to input their clan that is a group. like john doe is in clan “123” and their color is “Yellow”

image

i honestly dont know what you mean by this, from it seems its literally just some basic string stuff, but you’ll need to explain it a bit better before i can help you

The clan system allows players to join a specific in-game clan by associating with a Roblox group. Once a player is part of the group, their rank within the group will be reflected in their in-game name tag. The clan owner can customize their clan’s name, choose a color for the clan, and blacklist the maroon color, which is reserved for the game’s admin clan (used by game moderators). The group ID links the in-game clan to a Roblox group, automatically assigning players’ ranks based on their group membership.
im sleep deprived