Dialogue Module Font System Not Working As Intended

:grin: Hello everyone in the development community! This is my first post so far and this is a problem I’ve been having for a day and a half now. Sorry if I make any mistakes going over this…

  • So, I want to fix an issue relating to an advanced dialogue module I’ve been creating that makes it easy to change and customize it to someone’s needs.

  • The problem relates to fonts and most likely emphasizing since that’s a recent setting for dialogue I’ve been trying to add. Whenever I get to a certain point in a dialogue text module, it gives me an error saying Unable to assign property Font. EnumItem, number, or string expected, got nil.

  • I’ve tried debugging, looking online, and even got desperate enough to try and look into Assistant but none of that has worked.

Here is the main part that’s causing the error in the dialogue module. If you need other parts, I can send you those afterward since there are defined things here that are out of the code block.

local function BuildTheLine(ui,text_size,String,number,index,max_index,SettingsLetters,SettingsColors,SettingsEmphases,SettingsAnimations,Font)
	local LineSize = ui.AbsoluteSize.Y/max_index
	local CurrentLinePos = LineSize*index
	local CenterPos = CurrentLinePos+CurrentLinePos
	local Letters = {}
	local LastPosition = UDim2.new(0,0,CenterPos/ui.AbsolutePosition.Y,0)
	local LastSize = UDim2.new(0,0,0,0)
	local SumSize = 0
	for i=1,#String do 
		local TextLabel = Instance.new("TextLabel",ui)
		TextLabel.Visible = false
		TextLabel.BackgroundTransparency = 1
		TextLabel.RichText = true
		TextLabel.TextSize = text_size
		TextLabel.Text = SettingsLetters[i+number]
		local emphasis = SettingsEmphases[i+number]
		if emphasis == "i" then
			TextLabel.Text = "<i>"..TextLabel.Text.."</i>"
		elseif emphasis == "b" and not boldFonts[TextLabel.Font] then
			TextLabel.Text = "<b>"..TextLabel.Text.."</b>"
		elseif emphasis == "u" then
			TextLabel.Text = "<u>"..TextLabel.Text.."</u>"
		elseif emphasis == "s" then
			TextLabel.Text = "<s>"..TextLabel.Text.."</s>"
		end
		print("Emphasized")
		TextLabel.Font = Font
		TextLabel.TextColor3 = SettingsColors[i+number]
		TextLabel.Name = TextLabel.Text
		TextLabel.AnchorPoint = Vector2.new(0.5,0.5)
		TextLabel.TextStrokeTransparency = 0
		TextLabel.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		TextLabel.Size = UDim2.new(TextLabel.TextBounds.X/ui.AbsoluteSize.X,0,TextLabel.TextBounds.Y/ui.AbsoluteSize.Y,0)
		SumSize = SumSize+TextLabel.TextBounds.X/ui.AbsoluteSize.X
		local Offset = UDim2.new((TextLabel.TextBounds.X/ui.AbsoluteSize.X)/2,0,0,0)
		TextLabel.Position = LastPosition+Offset+UDim2.new(LastSize.X.Scale/2,0,0,0)
		table.insert(Letters,TextLabel)
		LastPosition = UDim2.new(TextLabel.Position.X.Scale,0,CenterPos/ui.AbsolutePosition.Y,0)
		LastSize = TextLabel.Size
		TextLabel.Visible = false
	end
	local Offset = (1-SumSize)/2
	for i,v in pairs(Letters) do
		v.Position = v.Position+UDim2.new(Offset,0,0,0)
	end
	return Letters
end

Here’s the part where the function is being used: (Apart of another larger function)

local Text = ConvertToText(Answer.Text)
	self.Gui.Main.Calculate.Text = Text
	local TextSize = 25
	LetterSize = TextService:GetTextSize(Letter,TextSize,self.Settings.Font,Vector2.new(10000,10000))
	local FrameSize = TextService:GetTextSize(Text,TextSize,self.Settings.Font,Vector2.new(self.Gui.Main.MainBounds.AbsoluteSize.X,10000))
	local words = gmatch(Text)
	local SettingsLetters,SettingsColors,SettingsEmphases,SettingsAnimations = SplitToSettings(Answer)
	local lines = math.floor(FrameSize.Y/LetterSize.Y)
	local line = 1
	local index = 0
	local String = ""
	local Letters = {}
	for i,v in pairs(words) do
		local save,save2 = String,index
		String = String..v
		local Size = TextService:GetTextSize(String,TextSize,self.Settings.Font,Vector2.new(10000,10000))
		if Size.X > self.Gui.Main.MainBounds.AbsoluteSize.X then
			local LettersLine = BuildTheLine(self.Gui.Main.MainBounds,TextSize,save,index,line,lines,SettingsLetters,SettingsColors,SettingsAnimations,self.Settings.Font)
			for _,l in pairs(LettersLine) do
				table.insert(Letters,l)
			end
			line = line+1
			index = #save+index
			String = v
		end
	end
	local LettersLine = BuildTheLine(self.Gui.Main.MainBounds,TextSize,String,index,line,lines,SettingsLetters,SettingsColors,SettingsEmphases,SettingsAnimations,self.Settings.Font)
	for _,l in pairs(LettersLine) do
		table.insert(Letters,l)
	end

And the dialogue text module: (Throws error at the seventh dialogue)

Settings = {

	Font = Enum.Font.GothamBold; --- Font for ALL text in dialogue

	PlayerColor = Color3.fromRGB(0,0,255); --- Player's text color

	[1] = {
		Text = {"Haaahhh...haaahhh..."}; --- Splitted text, that needs to add animations and colors to text
		--- How does it work:
		--- "Text"
		--- Color	
		--- Emphasise names ("Normal", "i", "b", "s", "u")
		--- Animation name ("Normal","Waves","Shakes")
		Colors = {Color3.fromRGB(255, 255, 255)}; --- Splitted colors, that aligns to splitted text
		Animations = {"Normal"}; --- Splitted animation names, that aligns to splitted text
		Emphases = {"Normal"}; --- Splitted emphasis names, that aligns to splitted text
		Character_Icon = "rbxassetid://5482508099"; -- Character's face during this dialogue, set to "Player" if you want player's Icon
		Character_Name = "someone"; -- If you have multiple characters chatting during dialogue, you can set name here. For player name set value to "Player"
		Function = function() -- If you want to do something when choose this happens
		end;
	};
	[2] = {
		Text = {"I overslept again!"};
		Colors = {Color3.fromRGB(255, 255, 255)};
		Animations = {"Normal"};
		Emphases = {"Normal"};
		Character_Icon = "rbxassetid://5482508099";
		Character_Name = "someone";
		Function = function()
			
		end;
	};
	[3] = {
		Text = {"But I caught you this time!"};
		Colors = {Color3.fromRGB(255, 255, 255)};
		Animations = {"Normal"};
		Emphases = {"i"};
		Character_Icon = "rbxassetid://5482508099";
		Character_Name = "someone";
		Function = function()

		end;
	};
	[4] = {
		Text = {"Maybe, but only because I decided to stop and wait for you."};
		Colors = {Color3.fromRGB(255, 255, 255)};
		Animations = {"Normal"};
		Emphases = {"Normal"};
		Character_Icon = "rbxassetid://5482508099";
		Character_Name = "Nerd";
		Function = function()

		end;
	};
	[5] = {
		Text = {"Eeehhhhh, you say that like you were thinking about ignoring me!"};
		Colors = {Color3.fromRGB(255, 255, 255)};
		Animations = {"Normal"};
		Emphases = {"i"};
		Character_Icon = "rbxassetid://5482508099";
		Character_Name = "someone";
		Function = function()

		end;
	};
	[6] = {
		Text = {"That's mean, you nerd!"};
		Colors = {Color3.fromRGB(255, 255, 255)};
		Animations = {"Normal"};
		Emphases = {"Normal"};
		Character_Icon = "rbxassetid://5482508099";
		Character_Name = "someone";
		Function = function()

		end;
	};
	[7] = {
		Text = {"Well, if people stare at you for acting weird I don't want them to think we're actually close or anything."};
		Colors = {Color3.fromRGB(255, 255, 255)};
		Animations = {"Normal"};
		Emphases = {"Normal"};
		Character_Icon = "rbxassetid://5482508099";
		Character_Name = "nerd";
		Function = function()

		end;
	};

Hope you guys can help me with this one! :smile:

I can’t believe I forgot to add where the error in the dialogue module script would occur…

It's the BuildTheLine function where the TextLabel's font is set to the font argument.

The BuildTheLine function in the for words loop is missing SettingsEmphases

It should be this instead

local LettersLine = BuildTheLine(self.Gui.Main.MainBounds,TextSize,save,index,line,lines,SettingsLetters,SettingsColors,SettingsEmphases,SettingsAnimations,self.Settings.Font)

:sweat_smile: Well, now I feel like a complete idiot. I’m surprised that such a problem had such a simple fix. I was stuck on it for a day and a half and it was all because of a simple mistake of leaving out the setting.

Thank anyway though : ) (I couldn’t put the smile and the eyes close together >m<)

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