Hello, I have a question as to whether it is possible to create a script via Instance.new() and edit what is inside, I am a new programmer and I really don’t know how I can change this value, thank you.
You can create a script with Instance.new()
but the LuaSourceContainer.Source
(which is the code that’s in it) is a locked property set to Plugin Security, meaning you can only edit it from a plugin, command bar (in studio), or in studio directly.
So your direct answer is: You cannot edit a script from a script, though you can create the script instance with Instance.new()
If you want to look into having code be executed from whatever you want without setting it up before hand, I’d look into loadstring()
. Loadstring executes code from a provided string argument so 'print("Hello World")'
into the loadstring
function would execute this piece of code, and end up printing “Hello World.” To enable it, you need to go to ServerScriptService and turn on the setting: LoadStringEnabled
.
Be warned: Having loadstring on is a dangerous setting. It opens you up to more vulnerabilities.
The roblox documentation puts it best:
This service houses just one property, LoadStringEnabled, which determines whether the loadstring function in Lua is enabled. It’s recommended to keep this disabled for security reasons, as misusing this function can lead to remote code execution vulnerabilities.
ServerScriptService | Documentation - Roblox Creator Hub
You could clone the script… but thats also assuming he doesent neee every script to be coustom to the thing its modifying