So I have a long string (what will be the source of a script) that is generated by a script and I would like to set another script’s Source to be this string
But the string is above 200k characters so it throws an error
My first thought was to just output the string to the output and copy and paste it from there but the problem is that Roblox compresses your output
So now I’m stuck and desperately need a solution
The only restriction is that the final script’s source must equal the original string exactly and the only assumption that can be made is that the string is over 200k characters
I think if you add random spaces before each line the code won’t get compressed. You could also try setting the value of multiple StringValues then copy the 200k-long chunks one at a time.
I’d like to know why you need a script this long in the first place. Maybe there’s another solution.
A simple but little elegant solution is to set each source up to the limit, generating multiple scripts. If you copy and paste those in notepad you can manually paste the result in a script as ctrl-v does not appear to have the same character limit. Be aware that it does take long and can cause studio to stop responding to work with such lengthy scripts.
I’ve done this before so fair enough. It does simplify the Lua constant table and would make the game load faster in theory, but I wouldn’t recommend doing it because makes debugging really tedious. I instead spent time implementing a Lua simplifier and compile process for my game. I think stravant has a public Lua minify plugin you could try modifying if the alternating space trick doesn’t work: https://www.roblox.com/library/197760456/Stravant-Minify-Beautify
Yea I think I will use that & it was my initial thinking to run the string through it except I got thrown an error so I’m trying to see if its a bug with his plugin or my script
edit:
good news it was a bug with my code (was adding a space instead of new line between modules so modules that had comments on the last line commented out first section of next module xd
also by doing this I’m definitely betting against having bugs(in the final version) (which I’m pretty confident about because really the only game specific code is simple things like UI & purchase handlers and complex things like physics (but I don’t think physics code throws errors))
You could try applying this snippet to the source to use an alternating space trick before printing:
local space = true
source = source:gsub("\n", function()
space = not space
return space and "\n " or "\n"
end)
It might break your code if you use multi-line strings.
I’d like to see the 200k limit removed from scripts, as I’ve hit it multiple times when working with big data sets in experimental projects. I could be wrong but I think the limit was initially introduced for replication reasons.
I don’t really want to take a risk with it, but on the bright side, after using stravant’s plugin the server side is down to ~114k
[Replication] I don’t think it really matters for scripts because I have Auto-updated API Dump / Reflection Metadata module saved as a static module and it is ~60k lines (thank god I’m not compressing it with the rest of my scripts lol)
I mean to say I don’t think the original reason the limit was added applies anymore, and that it should be relatively easy for an engineer to remove the limit (or raise the constant drastically).
Security through obscurity should never be relied upon. When the vulnerabilities are discovered, which will always happen with a popular game, you’ll have to rewrite your code. It’s equivalent to covering up instead of solving an issue.
Obscurity should only ever be used alongside proper security as an extra precaution.
You won’t even be able to copy and paste the source to get it to work. All scripts have a 200k character limit, regardless of whether you set it programmatically or manually.
I ran into this, like, 6 years ago when I was making a build tool and ModuleScripts hadn’t yet been introduced. I hacked around it with a bunch of loadstrings. You can technically do the same.
It’s a bit extreme, but if you have something unique in the string you can search for, you can get it straight from memory as long as it’s not garbage collected.