Counting total lines of a code during runtime

I’m making a splash text for my game, and I want to include the amount of lines of code in the game, similar to Minecraft. But when I try, it gives me this error:

23:46:48.480 The current thread cannot read ‘Source’ (lacking capability PluginOrOpenCloud) - Client - Title:62

Does this mean I would have to manually change the line count value each update?

1 Like

You can’t use Source during runtime. You could try making a plugin that adds an attribute “Lines” to all your scripts and update it whenever the scripts change.

2 Likes

Do you have a script to show us. So we can figure what the problem is?

You could probably make a plugin or line of code in the CommandBar that updates some intvalue every time the source changes and then you use whatever code you have to check for linebreaks.

1 Like

this is for functions only but you can try debug.info(level, "l")

Based on previous replies, I made this → LineCount.rbxmx which is a plugin that not only lets you set and update attributes containing the line count of scripts, but also comes with the ability to generate a module called LCM (LineCountModule), which you can use during runtime to get the amount of lines you got.

Do note that you cannot update anything during runtime, as it requires plugin-capabilities, however, what it will detect is if you clone already counted scripts or modules, or manually set a numerical “LineCount” attribute to a script or module.

Just put it into your local plugins-folder “C:\Users\YOUR USERNAME\AppData\Local\Roblox\Plugins” and it will work out of the box. The current one includes the default services visible in the explorer while in studio, which should be enough in most cases, however to add or remove services, you have to turn on PluginDebugService through studio settings, this allows you to edit the plugin’s code.
The targeted services table is at the top of the script. If changed, make sure to save and reload the plugin through PluginDebugService, and regenerate the LCM module, that’s it.

Final note: the plugin automatically updates each script when opening the game-file, or when the “LineCount” button is pressed in the plugins-tab. I did not go for automatically updating scripts due to possible performance issues, at least if we’re talking bruteforce-updating, you can of course change this if you’d like.