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:
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 β<β, which is the escape form of β<β, and any β>β with β>β.
1 Like
so when a player sends a message with the < character the rich text dosent work properly
Katrist
(Katrist)
January 4, 2024, 1:36am
#6
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("<", "<"):gsub(">", ">"):gsub('"', """) -- 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
system
(system)
Closed
January 18, 2024, 1:37am
#7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.