Hello! I’m trying to make the player’s name bold and a different color inside a dialogue system, how do I go about making that? Down below is the script and the format of the dialogue system:
Script:
local player = game.Players.LocalPlayer
local function typeWriter(s)
local newString
for i = 0, s:len(), 1 do
newString = s:sub(1, i)
if s:sub(i - 1, i -1) == "," then
wait(0.4)
elseif s:sub(i - 1, i -1) == "." then
wait(0.6)
elseif s:sub(i - 1, i -1) == "!" then
wait(0.6)
elseif s:sub(i - 1, i -1) == "?" then
wait(0.6)
end
script.Parent.Frame:WaitForChild("TextLabel").Text = newString
wait(0.01)
end
end
local function playingType()
typeWriter("Hello "..(player.Name).."! It's nice to see you playing this game!")
end
playingType()
Screenshot:
(If this is in the wrong category on the DevForum, then I’m sorry. I still see this as Scripting Support.)
Roblox’s RichText won’t work with this instance, as you are trying to do a type writer effect, and so the markups would not be applied until the section of text is complete.
I’d recommend you check out Defaultio’s custom RichText. It’s a few years old, but last time I used it, it worked well.
Yo. I’ve used Rich Text Markup for years now, and it’s not exactly the most performant solution since there’s so many Objects created so quickly within a short duration. If you’re not careful, you can easily freeze your game due to this limitation.
Mind sending a picture our way? (and the string you provided for the TextLabel)
This is discount bin way to fix the issue. I could not think of a better way at the moment.
I suggest trying the module that got linked over this awful code:
What it does is splits words found inside and into a ton of characters wrapped between and then writes them…
local function Typer(InputString)
local Words = {}
for Match in InputString:gmatch("%<?b?%>?%w+%<?%/?b?%>?") do
local IsBold = not not Match:find("%<?b%>%w+%<%/b")
Match = Match:gsub("%<b%>", ""):gsub("%<%/b%>", "")
table.insert(Words, {Match, IsBold})
end
local Letters = {}
for Index, Info in pairs(Words) do
local Word = Info[1]
local IsBold = Info[2]
for Letter in Word:gmatch(".") do
if (IsBold) then
Letter = "<b>" .. Letter .. "</b>"
end
table.insert(Letters, Letter)
end
table.insert(Letters, " ")
end
for i, Letter in pairs(Letters) do
Label.Text = Label.Text .. Letter
wait(.1)
end
end
Typer("My name is <b>" .. Client.Name .. "</b>. How are you?")