How to make custom rich text?

Title says it all. How can I make my own rich text system?

what do you mean “own system” for rich text?

(c)(255,0,0)Oh my god(c) ← appears red and NOT white or any other color.

well yeah because it follows RGB (RED, GREEN, BLUE) to get white, you do 255,255,255

nvm I made the system thx for your replies. any new replies are appreciated.

uhh, you’re welcome? ig (thirty)

You’d use string manipulations.

local Script = script
local TextLabel = Script.Parent

local String = "<color = \"Red\">Hello world!</color>"
local Color, Text = string.match(String, "^<color = \"([%a%s]+)\">([^<]+)</color>$")
TextLabel.TextColor3 = BrickColor[Color]().Color
TextLabel.Text = Text

--TextLabel's text color is red and its text is 'Hello world!'.

image

ah forummer you’ll be needed later. I have made the system but it has a error and as now I am taking a break ill tell you the error after 30 minutes k? please respond.

ok forum guy heres the script:

local Text = "(c)(c=123,123,123)Oh my god(c) if this works I will play (c)(c=123,255,255)Entry Point(c). :) :bruh:"

local Index = 1

local Emojis = {
	[":bruh:"] = 7770278986
}

local function IsInBound(Frame2, Frame1)
	if Frame2.AbsolutePosition.X < Frame1.AbsolutePosition.X or Frame2.AbsolutePosition.Y < Frame1.AbsolutePosition.Y then
		return false
	end
	if Frame2.AbsolutePosition.X+Frame2.AbsoluteSize.X > Frame1.AbsolutePosition.X+Frame1.AbsoluteSize.X then
		return false
	end
	if Frame2.AbsolutePosition.Y+Frame2.AbsoluteSize.Y > Frame1.AbsolutePosition.Y+Frame1.AbsoluteSize.Y then
		return false
	end
	return true
end

local function MakeLabel(Text,MainLabel:TextLabel,Parent,Checking,Color)
	local Label = Instance.new("TextLabel")
	Label.Parent = Parent
	Label.Text = Text
	Label.TextScaled = true
	Label.Font = MainLabel.Font
	Label.TextColor3 = Color == nil and MainLabel.TextColor3 or Color
	Label.BackgroundTransparency = 1
	Label.Size = UDim2.fromScale(0,1)
	Label.AutomaticSize = Enum.AutomaticSize.X
	Label.Name = Index
	Index += 1
	if Checking then
		game:GetService("Debris"):AddItem(Label,0)
		return IsInBound(Label,MainLabel)
	end
end

local function MakeImage(Id,MainLabel:TextLabel,Parent,Checking)
	local Label = Instance.new("ImageLabel")
	Label.Parent = Parent
	Label.Image = "rbxassetid://"..Id
	Label.BackgroundTransparency = 1
	Label.Size = UDim2.fromScale(1,1)
	local UIAspectRatioConstraint = Instance.new("UIAspectRatioConstraint")
	UIAspectRatioConstraint.Parent = Label
	UIAspectRatioConstraint.AspectRatio = 1
	Label.Name = Index
	Index += 1
	if Checking then
		game:GetService("Debris"):AddItem(Label,0)
		return IsInBound(Label,MainLabel)
	end
end

local Lines = 0

local function MakeLine(Parent:TextLabel)
	Index = 1
	local Frame = Instance.new("Frame")
	Frame.Parent = Parent
	Frame.Size = UDim2.new(1,0,0,Parent.TextSize)
	Frame.Position = UDim2.new(0,0,0,Parent.TextSize*Lines)
	Frame.Transparency = 1
	Lines += 1
	local UIListLayout = Instance.new("UIListLayout")
	UIListLayout.Parent = Frame
	UIListLayout.FillDirection = Enum.FillDirection.Horizontal
	UIListLayout.SortOrder = Enum.SortOrder.LayoutOrder
	Frame.Name = "Line "..Lines
	return Frame
end

local frame = MakeLine(script.Parent)

local richtable = {}
local strtable = Text:split(" ")

local split = Text:split("(c)")

for i,v in pairs(split) do
	local c = string.match(v, "%(.*%)")
	if c then
		table.insert(richtable,v)
	end
end

for i,notfixedword in pairs(strtable) do
	local space = i==strtable and "" or " "
	local word = notfixedword:gsub("%(c%)","")
	if word:match("%(.*%)") then
		word = word:gsub(word:match("%(.*%)"),""):gsub("%(",""):gsub("%)","")
	end
	local img = nil
	
	local color = nil
	
	for i,v in pairs(richtable) do
		if v:find(word) then
			local c = v:gsub("%(c=",""):gsub("%)",""):split(",")
			local r,g,b = c[1]:gsub("[^%-%d]",""),c[2]:gsub("[^%-%d]",""),c[3]:gsub("[^%-%d]","")
			color = Color3.fromRGB(r,g,b)
		end
	end
	
	for name,id in pairs(Emojis) do
		if name == word then
			img = id
			break
		end
	end
	
	if img then
		if MakeImage(img,script.Parent,frame,true) then
			MakeImage(img,script.Parent,frame,false)
		else
			frame = MakeLine(script.Parent)
			MakeImage(img,script.Parent,frame,false)
		end
	else
		if MakeLabel(word..space,script.Parent,frame,true,color) then
			MakeLabel(word..space,script.Parent,frame,false,color)
		else
			frame = MakeLine(script.Parent)
			MakeLabel(word..space,script.Parent,frame,false,color)
		end
	end
	wait()
end

as you can see I am making a custom text engine or system idk. the error is that if there is anything after the last (c) the word before it isnt considered a part of the rich text.

‘Entry Point’
This part specifically?

image
yea you see “Point” should be cyan but infact its not. If I remove the fullstop after the last (c) it works. but if i dont that happens. no errors at all!