How to change Team Chat/Whisper Bubble Color?

How would I go about making it so if a player is speaking in team chat, their chat bubble color is the color of their team, and if they are speaking in whisper their chat bubble color is a specific color.

For reference, I’ve attached an image of what I’m trying to do.
This is using Roblox’s new chat system.
image
image

I was able to change the color and text before a message is sent, and also detect if it’s a public message/team message/whisper message. Although I couldn’t figure out how to have the settings applied on a single message(the settings apply on every message visible), I am leaving this here hoping someone will find a solution:

--LocalScript inside StarterGui
local Chat = game:GetService("Chat")

local PlayerGui = script.Parent 

function RecursiveWait(names, t)
	names = string.split(names, ".")
	local current = PlayerGui 
	for i, name in pairs(names) do 
		current = current:WaitForChild(name, t) 
		if not current then 
			warn(name.." wasn't found!("..script.Name..")")
			return nil 
		end
	end
	return current 
end

local Scroller = RecursiveWait("Chat.Frame.ChatChannelParentFrame.Frame_MessageLogDisplay.Scroller", 5)
if not Scroller then return end 

local chatSettings = {
	BubbleDuration = 15,
	MaxBubbles = 3,
	BackgroundColor3 = Color3.fromRGB(250, 250, 250),
	TextColor3 = Color3.fromRGB(57, 59, 61),
	TextSize = 16,
	Font = Enum.Font.GothamSemibold,
	Transparency = .1,
	CornerRadius = UDim.new(0, 12),
	TailVisible = true,
	Padding = 8, -- in pixels
	MaxWidth = 300, --in pixels
	VerticalStudsOffset = 0,
	BubblesSpacing = 6,
	MinimizeDistance = 40,
	MaxDistance = 100,
}

function filterTextBoxes(textBoxes)
	for _, textBox in pairs(textBoxes) do 
		if string.find(textBox.Text, "{To") or string.find(textBox.Text, "{From") then 
			return "whisper"
		elseif string.find(textBox.Text, "{Team}") then 
			return "team"
		end
	end
end

Scroller.ChildAdded:Connect(function(child)
	if not child:IsA("Frame") then return end 
	local Label = child:WaitForChild("TextLabel", 5) 
	if not Label then return end 
	local messageType = filterTextBoxes(Label:GetChildren())
	if messageType == "whisper" then 
		chatSettings.TextColor3 = Color3.fromRGB(0, 0, 0) 
		chatSettings.BackgroundColor3 = Color3.fromRGB(255, 200, 0)
	elseif messageType == "team" then 
		chatSettings.TextColor3 = Color3.new(1, 1, 1) 
		chatSettings.BackgroundColor3 = Label.TextColor3
	else 
		chatSettings.TextColor3 = Color3.fromRGB(57, 59, 61)
		chatSettings.BackgroundColor3 = Color3.fromRGB(250, 250, 250)
	end
	Chat:SetBubbleChatSettings(chatSettings)
end)

This does seem to work, just like you said, for all the messages. Its a shame there isn’t a built in feature to set the settings of each message.

Your code is correct, but you need to add more inside your else statement.
You will want something like this:
try
if player:GetRoleInGroup(1234) == “Guest” then
chatSettings.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
elseif player:GetRoleInGroup(1234) == “Member” then
chatSettings.BackgroundColor3 = Color3.fromRGB(255, 255, 0)
elseif player:GetRoleInGroup(1234) == “Admin” then
chatSettings.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
elseif player:GetRoleInGroup(1234) == “Owner” then
chatSettings.BackgroundColor3 = Color3.fromRGB(0, 255, 255)
else
chatSettings.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
end
catch
chatSettings.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
end