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.
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.