I am trying to make a script of mine do Instance.new("LocalScript") and then insert code into that new LocalScript that the Server script just made is that possible?
Can you make a Script insert code into another Script and run it?
2 answers
No. Roblox removed the ability to set the Source of a script via scripts.
http://wiki.roblox.com/index.php?title=API:Class/Script/Source
However, if you'd like you can look into using loadstring(), which isn't recommended.
http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#loadstring
PLEASE NOTE Im not sure if this will work.
As computerchris stated, loadstring() is a possibility but isn't recommended. The only thing i could think of is usding a ModuleScript and requiring its code from another script. Im not sure if this would work in your case thoguh.
If this would work in your case however, id try something like this:
Insert a ModuleScript which should look something like this
local Module = {}
return Module
Then add in what code you would want to load or in this case require
local Module = {}
print("Hi")
return Module
Then in another normal script you can write
require(workspace.ModuleScript)
As i said im not sure if this will work as i quickly wrote it up, so if it doesnt stick with what computerchris said. Thanks.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
If you are trying to have the server compute certain parts of a script to prevent exploiting, you can use the return of a remote function/event.