Making a Specific Word a Different Color in Displayed Text

Hello there, dear Roblox developers and players.

I am trying to make a specific word “stand out” or make it a different color than the rest of the text when it is displayed on a board.

When I run the script the text will not even show up, as seen in this video.
robloxapp-20220316-2228249.wmv (1.2 MB)

I have tried this (the link listed) already but it is a little too complex and a lot of directions. I am also sure that this is not what I am looking for: How to make sections of text appear in different colors?

What I am trying to do is get a certain word to appear in a different color than the rest of the text on a display board(part) and not a GUI.

(I put this script under the part that the player will touch to display their name.)

local Players = game:GetService("Players")
local text = game.Workspace.Display.SurfaceGui.TextLabel --the blank board's text 
local db = false
local specW = {"TM11"} --special words
specW[1].Color = Color3.new(1,0,0) --making the color of the word red

script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	local human = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	if human then
		if db==false then
			db=true
			if player.Name=="TibetanMastiff11" then
				text.Text = "You are "..specW[1] --connecting the word with the sentence
			else
				text.Text = "False."
			end
		end
		wait(10)
		db=false
	end
end)

How would I make a specific word from the text stand out on a display board(part)?

4 Likes

I’m pretty sure you can achieve this by using RichText, couldn’t you, or is that not what you’re looking for?

According to the information on RichText here, you could do the following: I want the <mark><font color="rgb(255,165,0)">orange</font></mark> candy. I’ve attached an image here just so you can see if that’s actually what you’re looking for.

2 Likes

Like this?

            if player.Name=="TibetanMastiff11" then
				text.Text = "I want the <mark><font color="rgb(255,165,0)">orange</font></mark> candy."
			else
				text.Text = "False."
			end

I tried it but it won’t work.

2 Likes

Try this instead, your script is getting confused because you’re using the same quotation marks for both.

            if player.Name=="TibetanMastiff11" then
				text.Text = 'I want the <mark><font color="rgb(255,165,0)">orange</font></mark> candy.'
			else
				text.Text = "False."
			end
1 Like

Still won’t work. I have RichText on too.

1 Like

Odd, I just tested it with the following:

task.wait(10)

script.Parent.Text = 'Sorify is <mark><font color="rgb(255,0,0)">very very </font></mark> cool'

Which seemingly gave me this:

Would it be possible for you to show your new updated script once more, or what the sign says currently?

2 Likes

Updated and current script:

local Players = game:GetService("Players")
local text = game.Workspace.Display.SurfaceGui.TextLabel --the blank board's text 
local db = false
local specW = {"TM11"} --special words
specW[1].Color = Color3.new(1,0,0) --making the color of the word red

script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	local human = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	if human then
		if db==false then
			db=true
			if player.Name=="TibetanMastiff11" then
				text.Text = 'I want the <mark><font color="rgb(255,165,0)">orange</font></mark> candy.' --connecting the word with the sentence
			else
				text.Text = "False."
			end
		end
		wait(10)
		db=false
	end
end)

Updated and current video:
robloxapp-20220316-2324387.wmv (2.4 MB)

Also here is the workspace:

Here’s a few edits I made to get it to work! I was getting an error on the line specW[1].Color = Color3.new(1,0,0) which prevented it from running properly. Let me know if this works out for you now! Keep in mind this is just the edited script, there’s a couple things you no longer need in here as well as other things you should replace for best practice sake, but overall this is just an edit of your script!!

local Players = game:GetService("Players")
local text = game.Workspace.Display.SurfaceGui.TextLabel --the blank board's text 
local db = false
local specW = {"TM11"} --special words

script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	local human = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	if human then
		if db==false then
			db=true
			if player.Name=="TibetanMastiff11" then
				text.Text = 'I want the <mark><font color="rgb(255,165,0)">orange</font></mark> candy.' --connecting the word with the sentence
			else
				text.Text = "False."
			end
		end
		wait(10)
		db=false
	end
end)
3 Likes

Yes! It displays!
For whatever reason, I did not see the same error line you got before.

Ah, strange! Glad it’s working now! Originally you wanted to text to be red, I’m sure you know how to make the text red with RGB values but just in case feel free to replace the line with font color rgb with “rgb(255,0,0)”! :slight_smile:

1 Like
local specW = {"TM11"} --special words
specW[1].Color = Color3.new(1,0,0) --making the color of the word red

This would result in the error attempt to index string with "Color".

You index the first item/element of the table named “specW” which accesses the string value “TM11”, you then attempt to index a key/field inside this string object named “Color” which results in an error.

1 Like

I guess .Color only works with parts then? How would I have accessed the color of the string then if possible?

You can get a TextLabel’s text color by indexing its “TextColor3” property. This behavior is the same for similar GuiObjects.

1 Like