Text rendering function suddenly interprets variable as false when nothing has changed it

i am trying to make a custom text rendering system with UIListLayouts and Frames with TextLabels for each letter and custom rich text, so i can make dialogue with effects like this:
image

but, i am running into an issue where while the function is parsing the rich text tag, it stops parsing it when it reaches the parameters and instead renders the rest of the rich text tag (which isnt supposed to happen)

Screenshot

image

the text provided to the function was: "[shaky *magnitude=1*]SHAKING INTENSELY!!!![/shaky] [italic][bold]hi[/bold][/italic]"

Code:

function renderText(text : string, typewriterEffect : boolean)
	local currentTextStyles = {}
	local splitByWord = text:split(" ")
	local tickOffset = 0
	for i, word in pairs(splitByWord) do
		local newWordFrame = wordTEMP:Clone()
		local splitByLetter = word:split("")
		local tag = ""
		local parsingTag = false
		local escapeNextLetter = false
		local tagIsClosingTag = false
		for _, letter in pairs(splitByLetter) do
			if letter == "\\" and not escapeNextLetter then 
				escapeNextLetter = true
			elseif letter == "[" and not escapeNextLetter and not parsingTag then
				parsingTag = true
				print("start parsing tag")
			elseif letter == "/" and not escapeNextLetter and parsingTag then
				tagIsClosingTag = true
			elseif letter == "]" and not escapeNextLetter and parsingTag then
				print("stopped parsing tag")
				parsingTag = false
				if tagIsClosingTag then
					table.remove(currentTextStyles, table.find(currentTextStyles, tag))
				else
					print(tag)
					table.insert(currentTextStyles, tag)
				end
				print(currentTextStyles)
				tag = ""
			elseif parsingTag then
				tag ..= letter
			elseif not parsingTag then
				local newLetter = wordTEMP:WaitForChild("LetterTEMP"):Clone()
				local textToSet = letter
				if #currentTextStyles > 0 then
					for _, style in pairs(currentTextStyles) do
						if style == "bold" then
							textToSet = `<b>{textToSet}</b>`
						elseif style == "italic" then
							textToSet = `<i>{textToSet}</i>`
						elseif style == "rainbow" then
							spawn(function()
								while newLetter do wait()
									local hue = (tick() / 10) % 1
									newLetter.TextColor3 = Color3.fromHSV(hue, 1, 1)
								end
							end)
						elseif style == "wiggly" then
							local to = tickOffset
							spawn(function()
								while newLetter do task.wait()
									--print(to)
									local y = math.sin((tick() + to) * 2)
									newLetter.UIPadding.PaddingBottom = UDim.new((y) * .2, 0)
									newLetter.UIPadding.PaddingTop = UDim.new((y) * -.2, 0)
								end
							end)
						elseif style == "fastwiggly" then
							local to = tickOffset
							spawn(function()
								while newLetter do task.wait()
									--print(to)
									local y = math.sin((tick() + to) * 6)
									newLetter.UIPadding.PaddingBottom = UDim.new((y) * .2, 0)
									newLetter.UIPadding.PaddingTop = UDim.new((y) * -.2, 0)
								end
							end)
						elseif style == "shaky" then
							spawn(function()
								while newLetter do task.wait(.1)
									--print(to)
									local x, y = random:NextNumber(-.1, .1), random:NextNumber(-.2, .2)
									newLetter.UIPadding.PaddingLeft, newLetter.UIPadding.PaddingRight = UDim.new(x,0), UDim.new(x*-1,0)
									newLetter.UIPadding.PaddingTop, newLetter.UIPadding.PaddingBottom = UDim.new(y,0), UDim.new(y*-1,0)
								end
							end)
						elseif style == "big" then
							newLetter.TextSize = 40
						elseif style == "tiny" then
							newLetter.TextSize = 15
						end
					end
				end
				print(textToSet)
				newLetter.RichText = true
				newLetter.Text = textToSet
				if not typewriterEffect then
					newLetter.Visible = true
				end
				newLetter.Parent = newWordFrame
				newLetter.Name = "Letter"
				tickOffset += 0.2
			end
		end
		newWordFrame.Parent = textFrame
		newWordFrame.Visible = true
		newWordFrame.LetterTEMP:Destroy()
	end
	if typewriterEffect then
		for _, wordFrame in pairs(textFrame:GetChildren()) do
			if wordFrame:IsA("Frame") then
				for i, v in pairs(wordFrame:GetChildren()) do
					if v:IsA("TextLabel") then
						local s = v.TextSize
						v.TextSize = 1
						TS:Create(v, TweenInfo.new(0.1), {TextSize = s}):Play()
						v.Visible = true
						dialogueFrame.Dialogue:Play()
						wait(.02)
					end
				end
			end
		end
	end
end

i did add a print() statement where it sets the parsingTag variable to false, and when i checked the output there was no output from that print statement, and i searched through the whole script but i didnt find any other place where i changed the variable.

1 Like

bump
please i am going insane trying to fix this mess

random should be Random with a cap R

local x, y = random:NextNumber(-.1, .1), random:NextNumber(-.2, .2)
newLetter.UIPadding.PaddingLeft, newLetter.UIPadding.PaddingRight = UDim.new(x,0), UDim.new(x*-1,0)
newLetter.UIPadding.PaddingTop, newLetter.UIPadding.PaddingBottom = UDim.new(y,0), UDim.new(y*-1,0)
separate issue:

you’re checking for a string with 2 characters on a string that has a max of 1 character
if letter == "\\" and not escapeNextLetter then

is shaky the only one that doesn’t work?

  1. I made a variable named random which is a Random.new()
  2. Im not checking for 2 letters, \ is an escape letter so you can e.g. type " and ’ inside a string, and if you type a single \ then it wont show
    explanation: Strings | Documentation - Roblox Creator Hub
  3. shaky isnt the only one that doesnt work, this applies to all tags

try using this as the string
"[shaky*magnitude=1*]SHAKING_INTENSELY!!!![/shaky] [italic][bold]hi[/bold][/italic]"

I think it’s because you’re splitting your word by spaces and your text has spaces inside the [ ]

1 Like

aaaaaaaaaaaaaah thank you so much i was going insane trying to fix this

1 Like

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