String too long - Trying to edit source of script

Describe the bug

When trying to edit the source of a script via a plugin, it errors with “String too long”

image

Reproduction: (A plugin script)

local s = string.rep("OOF", 100000)

local thing = Instance.new("Script", workspace)
thing.Source = s

Why is this a problematic bug?

Currently developing a git integration plugin, and it requires modifying the source of the scripts to change to newer versions, and prepend git related data at the top of the script, and phantom forces has really large singular scripts, which this bug conflicts with.

The length of the script I am trying to modify has a string length of 300,000+ characters, and it seems the limit is about 200,000.

19 Likes

I’ve actually run into this issue before while trying to obfuscate or otherwise manipulate the source of a script, and having the limit raised would be helpful for my purposes. That being said, some testing shows me that 199,999 is a hard limit in all string properties.

I ran this code to test the max length of strings:

Be wary of running this because it’s going to take a long time because it’s not meant for speed.

local Script = Instance.new("Script")
local rep = string.rep
local pcall = pcall

local function Set(i)
	Script.Source = rep("-", i)
end

for i = 1, 2^32 do
	if not pcall(Set, i) then
		print(i-1) -- To get an accurate value
		break
	end
end

And got:

199999

I did the same thing but with the Value property of a StringValue and got:

199999

With the name of a StringValue:

199999

This makes me think this is an intentional limit and not a bug, but regardless it should be raised.

8 Likes

The limit has been 200k for many months now. It’s a problem for my obfuscation and my place statistics parser too. I just have to work around it and create a new script instances and stitch it together by hand.

3 Likes

I’ve looked into it in my own time, when you set the string of a script it makes it into a “ProtectedString” in the instance bridge of roblox. but in that process it calls “throwable_lua_tostring” a C function in the engine with a hardcoded size limit, which it seems that function was made for a past issue dealing with networking limitations.
That issue seems like it is no longer a issue that applies to the “ProtectedString” though, due to the fact they don’t send the source anymore. Instead they just send the bytecode rather then replicating the whole protected string.
I’d imagine using define macros it can be made a exception for studio for setting a “ProtectedString” on a script or just rather remove this functionality for setting a “ProtectedString” via lua in the end.

4 Likes

These network limitations may still apply in team create, but I’m pretty sure you can still paste strings longer than 200k (you just can’t manually set .Source from a script). I’ve worked on many projects that involve processing lots of data or auto-generating source, and this limitation is always frustrating.

1 Like

Good point, I disassembled the latest roblox version regarding serializing these strings rather then going off of old stuff. The actively used max payload size per a string can be found in the client flags. which is currently 96000000 bytes, judging by the size I think they overcame this limitation. But if they didn’t it would be nice to make the limit more reasonably higher with the current max payload size.

3 Likes

Just ran into this issue myself.

Using StudioService:PromptImportLocalAsset() and GetFileContentsBinary() i wanted to put the contents into a script for easy viewing but with larger files I’m unable to.

5 Likes

So far the only thing that can overcome this limitation is making a bot to upload the script and then inserting it from insertservice, because the deserializer doesn’t have this check. Another thing to note is sadly I don’t think roblox paid much attention to this problem and I don’t think they will have any intentions adjusting it anytime soon unless they need to.

3 Likes

This is still an issue. At least lift the limit for plugins, because this has ruined my Portal 2 map editor plugin as it exports VMF files which are very large. If anyone knows a workaround, LMK, please.

I was trying to make a Lua Code aggregator for easy printing of hard copy to read over my code (since Roblox doesn’t even have a printer command) and this got in my way. It appears that since I have to do

newScript.Source=newScript.Source..  (not formatExtraction and format(s) or "") ..   tostring(s.Source)

there’s no way out of this because it’s not like I can just “append” a smaller string to the big " .Source", no I have the do = .Source+new and that quickly adds up past the limit having to redraw the whole thing each and ever time. Just why? I’ve lost a rare, entire weekend to this dilemma.

I’d like this to be addressed.

Currently working on a snippet plugin with a friend and thought it would be a very nice idea to use it within my game, since I have to do a lot of repetitive pathing and snippets is exactly the thing I need to get by.

Turns out any modifications to the source is absolutely unfeasible in this script as it’s over 236,000 characters:

10:04:54.814 print(game.ReplicatedStorage.ModuleScripts.GameScripts.BattleAPI.BattleAPI2.Source:len())
10:04:54.816 - 236123

…which basically removes all ability for the snippets plugin to do its thing. This sucks.

Yes, this is extremely inconvenient for plugin development, I have multiple plugins that need to modify a script source but are unable to go past that limit, this forces users to split their scripts into more modules than they’d usually need to.

As someone mentioned earlier, there’s also no way to append to a string without concatenating to the original string which means that there are practically no workarounds apart from forcing the user to copy-paste stuff in manually.

It would be great to see this addressed.

Adding my vote for this issue to be addressed. I was making a plugin to save voxel data from terrain into scripts, but the materials and occupancies matrices exceed the string limit of script.Source – after two weeks of working on this script I am faced with potentially being unable to finish it just because of this. Very disappointing and frustrating.

If Roblox cares about improving/supporting the Terrain feature of the studio, this issue needs to be addressed. Either raise the limit for Plugin Development or provide a built-in alternative.

1 Like

I am sorry but I need to revive this, I think with the current limitations this threshold should be raised, it causes so many issues and a simple fix would be doubling it or just removing it by finding some workaround :man_shrugging:

Hi,

As announced recently, this is not the recommended way to handle updating script contents in Studio from Plugins any more. You should use ScriptEditorService:UpdateSourceAsync() which solves this limitation.

	local SES = game:GetService("ScriptEditorService")
	local scriptToUpdate = game.Workspace.Script 
	SES:UpdateSourceAsync(scriptToUpdate, function(oldContent)
		return string.rep("OOF", 100000)
	end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.