Does anybody know how to fix this Rich Text bug?!

Hello everyone, I have been working on my this kill confirmed thing for my fps game, And I turned on rich text to make some of the text have color. But for some reason it does this…

The script

repeat wait() until game:IsLoaded() == true
wait(5)
local KillConfirmed = "[+30XP] Kill Confirmed"
local PersonKilled = [[ [+30XP] <font color="rgb(0,85,255)">Verbalase_notreal</font> [MP7] ]]
workspace["Kill Confirmed Sound Effect"]:Play()
for i = 1,#KillConfirmed do
	script.Parent.Text = string.sub(KillConfirmed,1,i)
	task.wait()
end
wait(.75)
workspace.beep:Play()
script.Parent.TextTransparency = 1
wait(.1)
script.Parent.TextTransparency = 0
wait(.1)
workspace.beep:Play()
script.Parent.TextTransparency = 1
wait(.1)
script.Parent.TextTransparency = 0
for i = 7,#PersonKilled do
	script.Parent.Text = string.sub(PersonKilled,1,i)
	task.wait()
end

Any help is appreciated

2 Likes

It’s not a bug, your script type letters 1 by 1. I believe there’s already a plugin for this, let me try to find it.

What you’re doing is adding each character of a string, to a string. The string you’re taking characters from has the tag inside of it, that means the tag will not be complete until you finish adding each character to the final string.

To fix this, you must add the tag to each time you add a character to the final string.

You can do this by adding the tag to each time you update the new string, then clearing the new string.

local newStr = ""

for i = 1, #KillConfirmed do
	newStr = string.sub(KillConfirmed,1,i)
    newStr = [[<font color="rgb(0,85,255)">]]..newStr..[[<font color="rgb(0,85,255)">]]
    script.Parent.Text = newStr
    newStr = ""
	task.wait()
end

I accidently posted the reply, let me actually do the thing.

Also please make your code look nicer, shorter code does not mean better code, the parser will remove all the whitespace regardless, so it does not take longer to run with more whitespace, if that is the reason why your code looks like that. And another thing, wait() has been replaced by task.wait(), so use task.wait() for every use of wait(). There are quite a lot of reasons why it is better, you can find them here.

You should probably use the built in typewriter features that Roblox themselves made over this, but for something this simple, it’ll do the trick.

5 Likes

Ok I will wait

Why not use MaxVisibleGraphemes instead? It’s pretty simple actually, here’s a pseudocode to help you understanding:

local String = [[ [+30XP] <font color="rgb(0,85,255)">Verbalase_notreal</font> [MP7] ]] -- String to display message
local Displayer = script.Parent -- Path to TextLabel
local TextLength = 0 -- The length of the message

-- Now, for this to work we need to set the 'MaxVisibleGraphemes' property to 0 since 0 is the amount of characters that will be displaying(we will change it later)
-- You can either do it manually or through a script
Displayer.MaxVisibleGraphemes = 0

Displayer.Text = String -- You can also set the text manually or through a script

for First,Last in utf8.graphemes(String) do -- Loop through all string characters
    TextLength += 1 -- Update TextLength

    -- If you want to ignore whitespaces:
    local Grapheme = String:sub(First,Last) -- Get the text letter
    if Grapheme ~= " " then
        -- Not a whitespace!
        Displayer.MaxVisibleGraphemes = TextLength -- Update MaxVisibleGraphemes to match the current text length
        task.wait(0.05) -- You can change this to whatever you want
    end

    -- If you don't want to ignore whitespaces remove the if statement
end

Result:

4 Likes

Thank you

Sorry to bother you but what does UTF8 do

Although I’m not really experient with UTF, I’ll try my best to explain

UTF-8 is just an encoding format; any characters that can be written can be encoded. Basically, it can encode a character into bytes(UTF-8 uses 8-byte) and then the receiving end can decode the bytes back into characters using the same format. You can see more about UTF-8 on the developer hub or try to search on the devforum.

Hope this answers your question!

Also I’m a bit confused how this worked without showing the Rich Text thingy ;-;
Could You explain

Sure!

The reason why the RichText format didn’t show was because the text was already set but you couldn’t see it since MaxVisibleGraphemes was set to 0. In your old script you were typing the letters 1 by 1, therefore, the script has not yet recognized it as a RichText format, until you finished typing it.

If you still have any questions, feel free to DM me at any given time.

EDIT: I had to update the explanation because it was really late here and I was pretty tired, also I had to remove the drawings because you asked why the format didn’t show up and not how MaxVisibleGraphemes works.

Oh ok lol