Configuring RichText in a script?

Since Roblox’s solution for multiple colors in a single strand of text was RichText, I tried using it for my game. The issue is this is basically impossible when trying to set the Color within a script. I have the RGB values of the two colors I want, but the richText code isn’t properly formatting. Here:

events.PlayerEvents.PlayerDied.OnClientEvent:Connect(function(target, killer)
	local targetName = target.Name
	local killerName = killer.Name
	local targetTeamColor = Color3.fromRGB(255,255,255)
	local killerTeamColor = Color3.fromRGB(255,255,255)
	if game.ReplicatedStorage.Players:FindFirstChild(target.UserId) then
		if target.UserId ~= player.UserId then
			local targetTeam = game.ReplicatedStorage.Players[target.UserId].GameData.Team.Value
			local targetTeamColor = game.ReplicatedStorage.Gamemodes.Mode.Teams[targetTeam].Color.Value
		end
	end
	if game.ReplicatedStorage.Players:FindFirstChild(killer.UserId) then
		if target.UserId ~= player.UserId then
			local killerTeam = game.ReplicatedStorage.Players[killer.UserId].GameData.Team.Value
			local killerTeamColor = game.ReplicatedStorage.Gamemodes.Mode.Teams[killerTeam].Color.Value
		end
	end
	local feedGui = player.PlayerGui.GameGui.Feed
	local feedBar = feedGui.UIGridLayout.Sample:Clone()
	feedBar.FeedText.Text = "<font color= "rgb(255,0,0)"> Y35X </font> KILLED <font color= "rgb(0,0,255)"> GGEMoyer </font>"
end)

I can’t input the color3 values I want to begin with because the text won’t properly format.
How can I create multi-colored text labels? I see it in games like Arsenal, Mad Paintball, etc., where the kill feed has strings of text with multiple colors, but this solution doesn’t appear to work.

Have you checked this code?

rgb(255,0,0) and rgb(0,0,255) are intersected with the string.

You could replace the quotation marks with [[ and ]]

feedBar.FeedText.Text = [[<font color= "rgb(255,0,0)"> Y35X </font> KILLED <font color= "rgb(0,0,255)"> GGEMoyer </font>]]

An alternative would be

feedBar.FeedText.Text = "<font color= 'rgb(255,0,0)'> Y35X </font> KILLED <font color= 'rgb(0,0,255)'> GGEMoyer </font>"

So many ways to do the samething haha

You can also escape the double quotation marks in your string by putting a backslash before each quotation mark:

"example \""

This would show up on a text label as:

example "

So, in your case:
feedBar.FeedText.Text = "<font color= \"rgb(255,0,0)\"> Y35X </font> KILLED <font color= \"rgb(0,0,255)\"> GGEMoyer </font>"

1 Like