[SOLVED] Method exists but it says it doesnt

I am trying to make a keyword highlighter but
the Module script prints out an error that the HighlightText method doesnt exist

Screenshot 2023-05-10 205209

For me my module script seems fine and i dont know what could be wrong

local list = {
	["Grounded"] = "rgb(0,200,255)"
}

local function HighlightKeyword(Keyword: string)
	if typeof(Keyword) == "string" then
		if list[Keyword] ~= nil then
			return '<font color="' .. list[Keyword] .. '">' .. Keyword .. '</font>'
		else
			return Keyword
		end
	else
		error("keyword is not a string.")
	end
end

function list:HighlightText(Text: string)
	if typeof(Text) == "string" then
		local SplitTextLine = string.split(Text," \n ")
		local RecordedText = ""
		
		for i,v in pairs(SplitTextLine) do
			local splitline = string.split(v," ")
			local RecordedLine = ""
			
			for i2,v2 in pairs(splitline) do
				if i2 ~= #splitline then
					RecordedLine = RecordedLine .. HighlightKeyword(v2) .. " "
				else
					RecordedLine = RecordedLine .. HighlightKeyword(v2)
				end
			end
			
			if i ~= #splitline then
				RecordedText = RecordedText .. RecordedLine .. " \n "
			else
				RecordedLine = RecordedText .. RecordedLine
			end
		end
		
		return RecordedText
	else
		error("Text is not a string.")
	end
end

return list

Is “list” the table returned by the modulescript?

Your module is returning the table

local list = {
	["Grounded"] = "rgb(0,200,255)"
}

This mean that the function list:HighlightText and HighlightKeyword are not returned when you are using require(module_path) and thus does not exist. To return a function and a table, you need to follow the following syntax explained here ModuleScripts | Roblox Creator Documentation

You would then need to change list:HighlightText to list.HighlightText since list. is what you are returning at the end of the module.

the list table is being returned

i always used “:” and it worked fine i will now try “.”

Edit: I now did but the method doesnt run
Edit 2: it only works in local scripts somehow

Maybe your issue is similar to this one I’ve had not long ago.

Maybe the replies on the post can help you?
Edit: oops wrong link, fixed now

i checked and it isnt similar my problem is running a function from a modulescript

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