How can I make a certain part of text a specific color?

Is it possible to change the color on one word? and the rest be white, Like for example say there was a dialog like

“Hey! Its a red panda”

And red in specific would be color red?

Here is the specific part of my script in changing

	if Type == Enum.MessageType.MessageError then
		script.Parent.TextLabel.Text  = "MAKE THIS RED"..message .. "\n"
	end
1 Like

Yes, use RichText.
Read the documentation, because there are a lot of other ways you can use RichText for.

if Type == Enum.MessageType.MessageError then
	script.Parent.TextLabel.Text  = "<font color="rgb(255,0,0)">MAKE THIS RED"..message .. "</font>\n"
end

I did try that and it broke the script. Im not sure why (Richtext is on)

Oh yeah, my bad

if Type == Enum.MessageType.MessageError then
  script.Parent.TextLabel.Text  = 'MAKE THIS RED<font color="rgb(255,0,0)">'..message .. '</font>\n'
end
1 Like

Hey sorry i didn’t notice this earlier but i just noticed now, for some reason the newline doesnt work. I’m not sure why

Do you have RichText enabled for your TextLabel?

Yes, I do

image

Can you please send me the full script, so I can have some more information, please.

when you say full scripting, do you mean the FULL script or just the portion where its necessary because its really long considering everything. If you just want the portion im working on rn here

local function appendToGui(message, Type)
	if Type == Enum.MessageType.MessageError then
		script.Parent.TextLabel.Text  = '<font color="rgb(255,0,0)">'..message .. '</font>\n'
	end
end

for _, messageInfo in ipairs(game:GetService("LogService"):GetLogHistory()) do
	appendToGui(messageInfo.message)
end

game:GetService("LogService").MessageOut:Connect(appendToGui)

UIS.InputBegan:Connect(function(input, IsTyping)
	if IsTyping then return end
	
	if input.KeyCode == Enum.KeyCode.Semicolon then
		
		if enabled == false then
			script.Parent.Enabled = true
			enabled = true
		else
			script.Parent.Enabled = false
			enabled = false
		end
	end
end)

local function OUTPUT(Output)
	script.Parent:WaitForChild("outputframe"):WaitForChild("output").Text = Output .."\n"
end

(ignore the uis)

The scripts works perfectly fine for me, everything get’s printed with the set color
I added a few lines, maybe you can troubleshoot from this:

local UIS = game:GetService('UserInputService')
local enabled = true

local function appendToGui(message, Type)
	if Type == Enum.MessageType.MessageError then
		script.Parent.Text  = script.Parent.Text..'This is an error: <font color="rgb(255,0,0)">'..message .. '</font>\n'
	elseif Type == Enum.MessageType.MessageWarning then
		script.Parent.Text  = script.Parent.Text..'This is a warning: <font color="rgb(255,225,125)">'..message .. '</font>\n'
	else
		script.Parent.Text  = script.Parent.Text..'Everything else: <font color="rgb(255,255,255)">'..message .. '</font>\n'
	end
end

for _, messageInfo in ipairs(game:GetService("LogService"):GetLogHistory()) do
	appendToGui(messageInfo.message)
end

game:GetService("LogService").MessageOut:Connect(appendToGui)

UIS.InputBegan:Connect(function(input, IsTyping)
	if IsTyping then return end

	if input.KeyCode == Enum.KeyCode.Semicolon then

		if enabled == false then
			script.Parent.Enabled = true
			enabled = true
		else
			script.Parent.Enabled = false
			enabled = false
		end
	end
end)

local function OUTPUT(Output)
	script.Parent:WaitForChild("outputframe"):WaitForChild("output").Text = Output .."\n"
end

-- for testing

while true do
	print(math.random(1,5))
	task.wait(1)
	warn(math.random(5,10))
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.