Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

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.

2 answers

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.