Hello! I was wondering this for a while, is there anyway that a script can edit another scripts contents?
Example
(Doesn’t Work - Just Example)
script.Parent.Parent.Script.Code = print("Hello")
Hello! I was wondering this for a while, is there anyway that a script can edit another scripts contents?
(Doesn’t Work - Just Example)
script.Parent.Parent.Script.Code = print("Hello")
You cannot write through scripts, but you can write to script.Source
by running code in the command bar or through a plugin script only.
For example :
-- code in the command bar
local code = game.ServerScriptService.Script
code.Source = "Edited"
or
game.ServerScriptService.Script.Source = 'print("hello")'
-- note that you can't double-double quote a string, use for example, single quotation marks for strings including "double quotes"
Hi. Just so you know, it is also possible to create code during run-time and execute it! You’d need loadstring()
for that. It doesn’t let you edit script’s source though, which is what you needed.
You could also just use ModuleScripts, right?