Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you make a Script insert code into another Script and run it?

Asked by
NexeusX 137
6 years ago
Edited 6 years ago

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?

0
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. CPF2 406 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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

Ad
Log in to vote
0
Answered by 6 years ago

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.

Answer this question