GSub & Sub keep removing richtext tags

Hi,

In my textbox, I want all the text to be underlined. I am using gsub to remove all alphabets from it (numbers only) and sub to make the max characters to 4. The problem is richtext isn’t being ignored.

self.Connections:Connect(BarFrame:GetPropertyChangedSignal("Size"), function(...: any)
	self.TextBox.Text = "<u>"..tostring(math.round(BarFrame.Size.X.Scale * 100) / 100).. "</u>"
end)
	
self.Connections:Connect(self.TextBox:GetPropertyChangedSignal("Text"), function(...: any) 
	self.TextBox.Text = self.TextBox.Text:gsub("[^%d%.%-]",'')
	self.TextBox.Text = self.TextBox.Text:sub(1,4)
end)

Solution:

self.Connections:Connect(BarFrame:GetPropertyChangedSignal("Size"), function(...: any)
	self.TextBox.Text = "<u>"..tostring(math.round(BarFrame.Size.X.Scale * 100) / 100).. "</u>"
end)
	
self.Connections:Connect(self.TextBox:GetPropertyChangedSignal("Text"), function(...: any) 
	if UserInputService:GetFocusedTextBox() then
		self.TextBox.Text = self.TextBox.Text:gsub("[^%d%.%-]",'')
		self.TextBox.Text = self.TextBox.Text:sub(1,4)
	end
end)

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