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

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

Asked by
Dominical 215 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by 9 years ago
 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?

0
I know how to use functions..... Also, I want to make a new script with Instance.new() with code inside. Dominical 215 — 9y
0
I think downvoting may have been a little unfair, but whatever, will edit... crackabottle123 110 — 9y
0
Edited with some new info, sorry for not reading the question crackabottle123 110 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

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.

0
Oh and note: If there is a string in there put and ' in it. Not a " I'll show in example fireboltofdeath 635 — 9y

Answer this question