How do i get the amount of lines in a script from a script?
You can just scroll to the bottom of the script and count. Or you can use this plugin (I own it so I know that it is a safe plugin to use):
You cannot get the number of lines inside a script using another script.
As @XdJackyboiiXd21 stated, you can use a plugin to find the number of lines.
This is because Script | Roblox Creator Documentation is exclusively accessible through the Command Bar and Plugins.
Script.Source is considered a Protected String var so only permission 1 identities can access it.
The script is a plugin, can you give me a example?
There was a post about this 6 years ago on the ScriptingHelpers forum, here is the basic outline of what they found:
function getLines(s)
local lines = {};
local str = "";
for i = 1, string.len(s.Source) do
if (string.sub(s.Source, i, i) == "\n") then
lines[#lines+1] = str;
str = "";
else
str = str..string.sub(s.Source, i, i);
end
end
if (str ~= "") then
lines[#lines+1] = str;
end
return #lines;
end
And here is the link to the original post:
Can’t like a simple solution with the help of string.split()
work?
local ChoosenScript --Reference it yourself.
print(#string.split(ChoosenScript.Source, "\n"))
After all, it returns an array like table with lines divided into separate strings so you can just get the length of array like table.
So I was curious about this too, and was curious about how much code I’ve written for a project. Using the information I gathered here, I assembled this command for doing this:
local allScriptLines = 0 for index : number, descendant : Instance in game:GetDescendants() do if (descendant:IsA('Script') or descendant:IsA('LocalScript') or descendant:IsA('ModuleScript')) then allScriptLines += #string.split(descendant.Source, "\n") end end print(allScriptLines)
I don’t mean to revive a long since inactive thread at all, just wanted to post something here for those that do find it when looking to do what I wanted. As for getting it from a script, I don’t believe you can due to security reasons outside of the ROBLOX Studio environment as a plugin or executable command?