Can plugins edit scripts that they insert?

So basically I want to make a plugin that inserts a script, this script can then be edited by said plugin.

Like making functions and variables etc.

Is this possible? if so how can I do this?

2 Likes

Sounds like you are interested in checking out developer tooling to make life easier in Studio. I highly recommend checking out Rojo which is the standard tool used to edit your scritps outside of the script editor. Rojo uses powerful development tools like Visual Studio Code that are worth learning if you pursue a more general career or education in programming as well.

1 Like

You can edit a script’s source in a plugin using Script.Source.
Alternatively, you can use ScriptEditorService.UpdateSourceAsync.

1 Like

How come ScriptEditorService is nil? When I try to use a variable for it the variable doesnt exist! Why?

Are you using game:GetService("ScriptEditorService")? Using Script.Source is simpler tho, and plugins can edit all scripts.

1 Like

yes I am I can show you where I access it

How???

1 Like

Script.Source. For your plugin, it doesn’t sound like the player is going to have the script opened, so you wont need ScriptEditorService. Script.Source can only be used by plugins on everything or by regular script on scripts they created.

I see. But how can I actually use it? What methods does it have? I looked at the doc but I didnt see any

its just a string with the code inside (use ; for line breaks)

Can you show examples? Cause idk what that means

so the source of a script is the code inside and since you can add line breaks to strings you’ll have to use ; which in scripting just lets you have multiple lines of code on one line

Example: a script with the code

local part = Instance.new("Part", game.Workspace)
part.Name = "Test"
part.Position = Vector3.new(10,10,10)

would be
script.Source = "local part = Instance.new('Part', game.Workspace); part.Name = 'Test'; part.Position = Vector3.new(10,10,10)" (this is one line btw)

This works yayyy problem.
What if I want to put the code on multiple lines? cause as of now its only on one and Id like to put it on multiple. Thanks for all your help!

for multiple line replace the “” with [[]]

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