Create a plugin that writes to a script's source

Basically, i’am currently making a random-like plugin(Cannot tell you because its super secret and you would laugh at me), the issue is that, i want to insert an script, with an certain code, but here are some things that don’t let me do it:

I cannot put the script with the code i want, in the script that makes the plugin, because “script” is an nil value.

When i try creating an actual script, i would need to change the Source propertie of the script: Here is what i sort of tried:

local Code = [[ Code ]]

local newScript = Instance.new("Script")
newScript.Parent = workspace
newScript.Source = Code -- This part would error, because the "Code", has an Code which contains "script.Parent", and it clearly gave an error.

I have no actual ideas on how to do this now…

Also, sorry if this is really bad explained.

1 Like

I believe that Script.Source cannot be called in a script, only in the command bar and console. If you do, it will error.

Should i say what plugin i’am trying to make?

Did you first save the script you’re using as a local plugin?

Yes, i did, and i actually “learned” how to make plugins using that page.

Also:

Nice! You’ll also need to have it connected to the event of some plugin instance.

Two examples are

  • triggered event on pluginAction instance created by :CreatePluginAction()
  • clicked event from PluginToolbarButton instance

.Source should be in a string, if there’s string inside the code, consider using services like github, or, do a string escape.

Ok, i will actually tell what i want to achieve:

I, want to make an actual qPerfectionWeld inserter.

Anything to say? [30 charsssssss]

local selectedObjects = Selection:Get()
		local parent = game:GetService("Workspace") --makes default parent workspace 
		if #selectedObjects > 0 then --if they select somewhere parent sets to that
			parent = selectedObjects[1] --sets parent to slected
		end
		newScript.Source = "your script..." --put your script here
		newScript.Parent = parent --sets script parent to above
		CHS:SetWaypoint("NewScript") --sets a waypoint so if you ctr z it works

Hope this helps! even if it is 3 years later maybe it can help someone else

The script is incomplete. If someone is in fact looking for a way to do this (since I doubt it), it is as simple as writing a normal script.

local myNewScript: Script = Instance.new("Script");
myNewScript.Source = [[print("Hello World")]];
myNewScript.Name = "Created by Plugin";
myNewScript.Parent = workspace;

This will run every time the plugin is loaded, meaning every time you open a game inside of Studio, a new script will be created. One should always invoke some functionality per the user’s input, such as through PluginToolbarButtons.

One difference between code that runs in-game and code that runs inside Studio is that they have different permissions. Only the command bar and plugin scripts can read/write the Script.Source property, since it is marked as a Plugin Security member (see here).

Anyway, please understand that 3-years ago me had an English problem.

5 Likes

yes i forgot to include a ed and adding the new script but if you want the selection then you should use above.

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