How to get each line of a scripts source?

I have made a script which gets the scripts source and puts it in a for loop for to print each line (note: I am doing this in a local plugin):

local source = script.parent.source
for i, line in ipairs(source) do
	print(line)
end

When i ran the script it did nothing. Is this how you are suppose to get each line of a scripts source?

2 Likes

Does it throw an error? And what’s the value of the source?
Script.Source returns a string and you can’t use an ipairs on a string.

Are you looking for string.gmatch?

for line in soruce:gmatch("[^\n]+") do
    print(line);
end;
2 Likes