i have been wanting help on this for a long time im trying to create a script builder and cant seem to know how i can make it on my game so it can run local scripts --My Attempt
script.Parent.TextButton.MouseButton1Down:connect(function() local codetoexecute = script.Parent.TextBox.Text local scripttable = {} local function runInSandbox(f) --get the old function environment local oldenv = getfenv(f) --create a new one local newenv = setmetatable({}, { __index = function(_, k) if k:lower() == 'game' or k:lower() == 'workspace' or k == 'Instance' then --that prevents any instances being accessed return nil else --but otherwise defaults to the old one return oldenv[k] end end }) --call the function in its new environment setfenv(f, newenv) f() end local func,err = loadstring(codetoexecute)() table.insert(scripttable,codetoexecute) end)
You cannot use loadstring()
in LocalScripts.
What script builders do is they make an api on own web hosts which uploads a LocalScript with the specified source as a model to roblox using a dummy account, and then returns the model id which can be used with LoadAsset()
or require()
(if they make it a ModuleScript
with a LocalScript
parented to it).