Typewriting Shows Richtext

Hello!

I was trying to typewrite a label which includes richtext. This turned out to be an issue when it typewrites the progression of the Richtext in the script. Example: it typewrites this; <font color='rgb(255, 0, 0)'><b>it</b></font>

Here’s the code:

local label = script.Parent
label.RichText = true

local function typewrite(object,text,length)
	for i = 1,#text,1 do
		local sound = Instance.new("Sound")
		sound.Parent = game.Workspace
		sound.SoundId = "rbxassetid://9120299506"
		sound.Name = "DialogSound"
		sound:Play()
		object.Text = string.sub(text,1,i)
		wait(length)
	end
	for i,v in pairs(game.Workspace:GetChildren()) do
		if v.Name == "DialogSound" then
			v:Destroy()
		end
	end
end

typewrite(script.Parent, "Objective: Flash your camera when you see <font color='rgb(255, 0, 0)'><b>it</b></font>.", 0.05)

I hope there is a way to solve this. Thank you so much for your help! :slight_smile:

Edit: I forgot to include, after typewriting the whole progression, it turns red and bolded as i wanted. The only problem is that it shows the < bold, color > thing. THanks

Hi!

The old method of using string.sub for type writing effect has now been phased out. Use TextLabel.MaxVisibleGraphemes instead.

You can get the display length of richtext using utf8.graphemes()

Roblox has also given a tutorial on how to implement a typewriter effect using this new setup: UI Animations | Documentation - Roblox Creator Hub

I will highlight this specific section of the code for your convenience:

local index = 0
for first, last in utf8.graphemes(displayText) do
	index += 1
	guiObject.MaxVisibleGraphemes = index
	task.wait(delayBetweenChars)
end
2 Likes

Thank you so much! I’ll check out if it works. Have a good one

1 Like

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