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

How to use 'Instance.new("Script")' with code inside it?

Asked by
EteraW 77
5 years ago
Edited 5 years ago

Please help me. I search it in google. and i found 2 ways.

1.Source

local script = Instance.new("Script",workspace)
script.Source = 'print("Hello world!")'

But this isn't working anymore.

2.loadstring

local script = Instance.new("Script",workspace) --why did he Instance a script? ( EteraW )
code.Value = 'print("Hello world!")'
loadstring(code.Value)()

This look like to work. But I don't know how to stop the script.

script:Destroy() doesn't stop the script.

Please help. I'm confused now!

0
why would you need to do this? just clone the script for replicated or storage. Thepoint13 99 — 5y
0
I want player to put their script in text box and run the script EteraW 77 — 5y
0
It's impossible to do so. Cloning a script copies its code over, but attempting to write to it from another script is not possible. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
2
Answered by
Arkrei 389 Moderation Voter
5 years ago

You cant write code to a script after creating it with a script, you COULD use a loadstring but personally I prefer having a disabled script somewhere, then moving it or cloning it somewhere and making the disabled property false. However if you really want to use loadstrings, make sure the property in ServerScriptService called loadstrings enabled is true, however beware this can be the target of exploiters

0
This may be the best way. Thank you! EteraW 77 — 5y
Ad

Answer this question