How to script something that creates a script with a script in it?

Hello! So is there a way to make a script that creates a script with a script inside of it? This sounds pretty confusing but what I want to do is something like that:
For example you click on an object and then a GUI pops up. You can type a script into that GUI. After pressing done, a new script will get created with the script that you’ve typed into that GUI.

I thought I had to do something like

local s  = Instance.new("Script", game.ServerScriptService)
s.Source = textLabel.Text --the script that the player has typed in

but that doesn’t work. It keeps erroring: The current identity (2) cannot Source (lacking permission 1)

1 Like

You can’t do this it can only be done in PLUGINS

1 Like

Only plugins can modify a script’s source, otherwise exploiters could steal scripts

2 Likes

No. You can only use the Source property of a script through the command bar or through plugins. If you really wanted this though, you can go to the properties of ServerScriptService and turn on LoadStringEnabled. The loadstring method can only be used on the server, unfortunately. This means you will need a RemoteEvent if you’re making a script builder.

This is generally frowned upon since it can allow exploiters to execute arbitrary code on the server.

@WishingTie09120 clients get bytecode form local scripts and modules so they can decompile them anyway.

3 Likes

Doesn’t bytecode have it’s limitations? For example variable names cannot be retrieved, unlocking script.Source would give full access

1 Like

Yes, Luau doesn’t send local names (and upvalue names) to the client anymore, and clients don’t receive source anyway. Just the bytecode

2 Likes

There are other ways that you can use loadstring though without needing to enable LoadStringEnabled, If you want to know about it you can reply to this or contact me on my discord. ryan10197#0691

1 Like