Richtext dosent work with this letter [<]?

I have been working on a simple custom chat for my game with richtext. But when some sends a message with this letter [<] this happeneds:

image

Script:

RemoteEvent.OnClientEvent:Connect(function(plr,Chat)

	local Text = script.Parent.Parent.TxtFolder.TextLabel:Clone()
	Text.Visible = true
	Text.TextColor3 = plr.TeamColor.Color
	Text.Parent = script.Parent.Parent.ChatBox

	Text.Text =  plr.Name..[[<font color="rgb(255, 255, 255)">]].." : "..Chat..[[</font>]]
	
end)

Writing on the Devforum, can you show me how it should look? Theres too many < so not sure which one you want.

FYI: β€˜<’ is a character not a letter

Hey! Is the Richtext Enabled in textlabel?
Try this
Yourname :Hey!

That’s because β€œ<” is used to begin a tag like <font>, and even when a player sends one in a message, RichText will still try to make sense of it.
You can use string.gsub to skim through the text and replace any β€œ<” with β€œ&lt;”, which is the escape form of β€œ<”, and any β€œ>” with β€œ&gt;”.

1 Like

so when a player sends a message with the < character the rich text dosent work properly

You have to replace all special characters like β€œ<”, β€œ>”, and β€œ&” with their escape forms as @ProgrammerOnCoffee said.

Code:

RemoteEvent.OnClientEvent:Connect(function(plr,Chat)

	local Text = script.Parent.Parent.TxtFolder.TextLabel:Clone()
	Text.Visible = true
	Text.TextColor3 = plr.TeamColor.Color
	Text.Parent = script.Parent.Parent.ChatBox
	
	Chat = Chat:gsub("<", "&lt;"):gsub(">", "&gt;"):gsub('"', "&quot;") -- etc

	Text.Text =  plr.Name..[[<font color="rgb(255, 255, 255)">]].." : "..Chat..[[</font>]]

end)

You need to do the rest of the escape forms, I gotta go do something else right now. If you need help, feel free to ask, I’ll help later.

2 Likes

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