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

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

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!

3 comments

0

why would you need to do this? just clone the script for replicated or storage.

0

I want player to put their script in text box and run the script

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.

1 answer

✓ Accepted answer

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

1 comment

0

This may be the best way. Thank you!

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