Script executing script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    the ability to execute a script you type in a text box

  2. What is the issue? Include screenshots / videos if possible!
    it doesn’t let me do it, it outputs in error I don’t understand what it means

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking on google + devforum but nothing helped. :sad:

here is the execute button script

script.Parent.MouseButton1Up:Connect(function()
	local s = game:GetService("ReplicatedStorage").executorCloner:Clone()

	require(game.MainModule).editScript(s, script.Parent.Parent.ScrollingFrame.TextBox.Text)
	wait(0.4)
	s.Enabled = true
	
end)

(MainModule is a module automatically created in every game)

here is the video I recorded of it


can anyone help me with this?

What is going on here? You’re attempting to use a method inside of the require function?

Are you using loadstring?

what’s loadstring? also this is a script I made 1+ year ago

edit: changed the script to

script.Parent.MouseButton1Up:Connect(function()
	local mainModule = require(game.MainModule)
	local s = game:GetService("ReplicatedStorage").executorCloner:Clone()

	mainModule.editScript(s, script.Parent.Parent.ScrollingFrame.TextBox.Text)
	wait(0.4)
	s.Enabled = true
	
end)
1 Like

loadstring has been around for a while.

Are you using ScriptEditorService? That only works in plugins which is probably why you’re getting that error

I am using the MainModule script that roblox places in every game

Just go to ServerScriptService and enable LoadstringEnabled (in the Explorer edit its properties)

Then all you gotta do is call Loadstring (only on the server)

Only problem is that loadstring is insecure and hackers can utilize it for themselves but if you’re willing to risk that then go ahead

-- example
local ex = "print(\"The Output says hi\")"
loadstring(ex)()
-- output: The Output says hi

I’m unaware of that. And I meant like internally.

Could you paste the contents of that script here?

local module = {}
function module.editScript(s, code) 
	s.Source = code
end
return module

1 Like

Oh alright so what’s “executorCloner”?

its an empty script that the execute button pastes the script typed in to it and runs it

1 Like

Ok yeah I think it has something to do with ScriptEditorService being out now so maybe Roblox halted the ability to edit script sources normally (maybe?)

So what i would do instead is make it fire a remoteEvent to the server and then you can follow the steps in my other post

here

and ya should be good

I still don’t know what loadstring is or how to use it…

1 Like

take a look at this post

no changes to this script

script.Parent.MouseButton1Up:Connect(function()
	local mainModule = require(game.MainModule)
	local s = game:GetService("ReplicatedStorage").executorCloner:Clone()

	mainModule.editScript(s, script.Parent.Parent.ScrollingFrame.TextBox.Text)
	wait(0.4)
	s.Enabled = true
	
end)

make a remote event


then make your module fire the event

local event = path

local module = {}
function module.editScript(code) 
	event:FireServer(code)
end
return module

on a server script, recieve it

local event = path

event.OnServerEvent:Connect(function(code)
   loadstring(code)()
end)

and boom there’s your example

there is no errors now but nothing happens?
script under the execute button

script.Parent.MouseButton1Up:Connect(function()
	local mainModule = require(game.MainModule)
	
	mainModule.editScript(script.Parent.Parent.ScrollingFrame.TextBox.Text)
	
end)

MainModule

local event = game:GetService("ReplicatedStorage").Event

local module = {}
function module.editScript(code) 
	event:Fire(code)
end
return module

script in ServerScriptService

local event = game:GetService("ReplicatedStorage").Event

event.Event:Connect(function(code)
	loadstring(code)()
end)
1 Like

Is this a RemoteEvent and not a bindableevent?

BindableEvents only communicate one way (if you’re calling :Fire on the client only another client script can receive it… vice versa)

I used a bindable event since all the scripts are server-sided

1 Like

Oh then you don’t even need to fire the bindableEvent, you can just call Loadstring in your module

Also I have school tmmr :neutral_face: so I can’t really respond after this (maybe but it’ll take a couple hours)

Script sources needed plugin level permissions to be changed by a script

You will need a remote event for that otherwise the text will always be nil as it isn’t replicated to the server. You could also then just leave all the server code in that 1 script then as their isn’t much to it and it is just simpler