TextLabel not displaying the right RichText

So I have a dialog system that supports richtext and for some odd reason, whenever the 2nd dialog shown in this video gets played the 1st one’s italics become bold.
It’ll hopefully make more sense when you watch the video. (my apologies if it’s a little low quality I had to compress it)

The code for this is displayed below, I don’t know how this could possibly be affecting anything…
If you need further explanation please tell me.

	local function typewrite(str: string,shadowStr: string?,label: TextLabel,speed: number,speedChanges: {})
		--The variables that matter are str, which is the text being displayed, and label, which is the text label being changed here.
		label.MaxVisibleGraphemes = 0
		label.Text = str

		local display = label.ContentText
		label.Shadow.Text = shadowStr or display
		label.Shadow.MaxVisibleGraphemes = 0
		local count = 0
		for _ in utf8.graphemes(display) do
			count += 1
		end

		for i = 1, count do
			label.MaxVisibleGraphemes = i
			label.Shadow.MaxVisibleGraphemes = i
			sound:Play() --"sound" does exist, don't worry, this is simply a snippet of the entire code.
			if speedChanges[i] then
				speed = speedChanges[i]
			end

			local currentchar = display:sub(i,i)

			if currentchar~=" " then
				task.wait(speed) 
			end
			--end
		end
	end

I have already tried printing out the text that’s in the TextLabel, the RichText tags showing up are the correct ones, which are the <i>text</i> ones.

There’s a possibility that this could just be some odd bug but I want to know if I could fix this…?

Was able to fix it!

Turns out, this is a bug. For some odd reason, if you replace a TextLabel’s Text property to something using rich text while the last Text it had also used rich text, it replaces the rich text in the new one to use the previous rich text that was used. Not sure if this is only with bold and italics but those are the only two I’ve tested with.

The way I fixed it was by setting the TextLabel’s Text property to an empty string, then doing a task.wait() afterwards.

--script.Parent being a TextLabel

script.Parent.Text = "<i>italics</i>" --with this script, this'll show up as italics.
task.wait(3)
script.Parent.Text = "<b>bold</b>" --but this will ALSO show up as italics.

--to fix this, I did this
script.Parent.Text = "<i>italics</i>"
task.wait(3)
script.Parent.Text = ""
task.wait()
script.Parent.Text = "<b>bold</b>"
1 Like

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