How to find what line something is located on? (via Plugin)

Is there a way that I could find where certain text is located in a script using a plugin?

For example, I use script.Source to get the script, but how could I see what line an if statement is on?

Thanks in advance.

1 Like

could make a table of all the different lines that have \n and then get the index of the table item

local function findCodeLine(Script, code)
	local Lines = Script.Source:split("\n")
	for i, v in pairs(Lines) do
		if string.find(v, code) then
			return {
				Line = i; 
				Code = v; 
				SearchIndex = code;

-- The code below here is just an example, you can remove it if you wish

local theScript = game.Workspace.theScript
local codeLine = findCodeLine(theScript, "Test")

if codeLine then

thanks so much!

(3O characters)

Also, if you’re having issues finding the code line because of capitalization, you can just lower the Source with :lower() before splitting it:

local Lines = Script.Source:lower():split("\n")