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

How would I make a new script instance with code? [SOLVED]

THIS IS SOLLLVVVEDDDD!!!!!!!!

So I remember a way that you could make a new script within a script and could make the new script have code in it.

It was something like this:

local script=Instance.new("Script")

script. I DONT KNOW WHAT TO PUT HERE = [[

print("Hello world!")
 -- You could put a whole script in here.

]]

2 answers

 Instance.new("Script",game.Workspace).Source="print(\"Hello World! v2\")"

Although script.Source is locked so this method would not work.

Perhaps have the script pre made in ServerStorage and then clone it?

3 comments

0

I know how to use functions..... Also, I want to make a new script with Instance.new() with code inside.

0

I think downvoting may have been a little unfair, but whatever, will edit...

0

Edited with some new info, sorry for not reading the question

Here try this. I do not promise anything

script = Instance.new("Script", workspace)
code = Instance.new("StringValue", script)
code.Value = "InsertScriptHere"
loadstring(code.Value)()

That loads the code's value as a script. If you have a string?

script = Instance.new("Script", workspace)
code = Instance.new("StringValue", script)
code.Value = "print('Hai')"
loadstring(code.Value)()

Note: I didn't put " because that'd error it. I put an ' so then it doesn't mess with the string it is in.

1 comment

0

Oh and note: If there is a string in there put and ' in it. Not a " I'll show in example

This discussion is preserved as it was. New answers, comments, and votes are closed.