I have an idea for a short game, and in the game, certain players would get access to this console where they can write out a command and when they press enter it creates a new script instance, executes the command, then destroys the script. I know how to do everything except changing the code in the script. Thank you for taking the time to read this all.
You need to use loadstring
. loadstring
returns a function based on code from the string you pass (if it doesn't error) that you can execute. This is very dangerous, so you will need to sandbox it by limiting what it can access. You do this by setting the function's environment.
local code = [[ for i = 1, 10 do print('rafor is cool') end ]] local newEnv = { print = print -- and so on } do -- put it in a different scope local success, err = pcall(function() loadstring(code)() end) end
You need to set ServerScriptService.LoadStringEnabled
to true however.
Reply with further questions,
and please mark as correct if this solution works for you!