I am trying to make a keyword highlighter but
the Module script prints out an error that the HighlightText method doesnt exist
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
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.