Conditional erroring while using a module script

Could be that I’m tired, and cannot see where I errored, but I have been trying to fix this for a while now and I give up haha

I’m working on a rich text reformatting function in a module script, since I want to use a typewriter effect for my dialogues; however there are words in the dialogue that I want to highlight a certain colour. (also if someone has a good way of doing this, please let me know! this is what I’ve come up with - )

in my module script below, I try to find a specific word in a string, which returns a number to which it starts and ends in the string. with this, I’m going to concatenate the highlighted word and continue the loop (but this is all I have so far:

local DialogueSettings = {}

DialogueSettings.DialogueColors = {
	["Pink"] = "rgb(233, 107, 255)";
	["Orange"] = "rgb(255, 197, 62)";
	["Green"] = "rgb(103, 255, 141)";
	["Red"] = "rgb(255, 73, 73)";
	["Purple"] = "rgb(170, 85, 255)";	
}

DialogueSettings.DialogueCharacter = {
	
	["Becca"] = {
		Cheerful = "";
		Happy = "rbxassetid://11314987460";
		Shocked = "";
		Joyful = "";
	};
	
	["Bill"] = {
		Happy = "";
		Dissatisfied = "";
		
	};
	
	["Jessie"] = {
		Cheerful = "";
		Embarassed = "";
	}
	
}


function DialogueSettings.SeparateRichText(Text,HighliteSubject,HighliteColor)
	print(Text)
	if string.find(Text,HighliteSubject) then
		print(string.find(Text,HighliteSubject))
	end
	
end

DialogueSettings.SeparateRichText()
return DialogueSettings

In the script, I try to call the module for testing purposes (local script):

local DialogueSettingsMod = require(script.DialogueSettings)

local DString = "Hello, Becca! How do you do?"

DialogueSettingsMod.SeparateRichText(DString,"Becca")

Resulting in the error:

meaning that in my conditional in the module script, its not receiving the string, but rather nil.

This is my hierarchy:
image

Any help would be amazing! thank you!

I don’t know if this has anything to do with the error, but typically I put modules in ReplicatedStorage (For cases where LocalScripts use it) and ServerStorage (For cases where LocalScripts don’t use it), so maybe try putting it in ReplicatedStorage?

I tried doing this, I received the same error unfortunately :frowning:

Wait what does the print statement put into the console before the code uses string.find?

It prints out nil, I even tried manually writing in a string in the local script instead of using a variable, get similar results

Maybe try initializing the function like:

DialogueSettings.SeparateRichText = function(Text,HighliteSubject,HighliteColor)
	print(Text)
	if string.find(Text,HighliteSubject) then
		print(string.find(Text,HighliteSubject))
	end
	
end

I actually tried that as well believe it or not haha :joy:

1 Like

OH!
It’s this line!

DialogueSettings.SeparateRichText()

Either remove it or check that none of the parameters are nil/invalid.

Holy crap I really am tired LOL

Thank you for pointing that out lol I feel like an idiot

Nah don’t be, we all do something like this sooner or later, but I do recommend having a conditional to check if none of the values are nil, and using the warn function if there are nil values, so nothing breaks.

1 Like

Good idea, I’ll probably add that in, thank you again!

Sometimes all it takes is someone to proof read your code lol

1 Like

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