Typewriting Label Shows Progression of 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 a video of the issue.

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:

(OMG I JUST REALIZED I ACCIDENTALLY HAD MY OBS SET TO THIS RANDOM VIDEO OF A GUY AT THE START I APOLOGIZE)

I recommend using the MaxVisibleGraphemes property instead, this way you can set the text before running the typewriting, and you don’t need a loop either. Just tried it with RichText and it works, here’s an example of how you can use it:

local TS = game:GetService("TweenService")
local function typewrite(str: string, txt: TextLabel, tim)
	local l = string.len(str)
	txt.MaxVisibleGraphemes = 0
	txt.Text = str -- set text -> richtext does its magic but doesn't appear to user yet because of line above
	local tw = TS:Create(txt, TweenInfo.new(tim), {MaxVisibleGraphemes = l})
	tw:Play() -- progressively increase MVG for typewriting effect based on str length
	tw.Completed:Once(function()
		task.wait(3)
		txt.MaxVisibleGraphemes = 0 -- to hide the text a bit after typing is done
	end)
end
2 Likes

Thanks man! I appreciate it greatly! :slight_smile:

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