Function in loadstring

Hi, So I tried using the loadstring function and it works pretty well and Im using it to create a Lua Executor game.

What I’m getting errors about is, It sometimes returns this response in the console, I don’t really know whats causing it.
The error response: PlayerGui.ScriptExecutor.MainFrame.ClientExecuteButton.LocalScript:21: attempt to call a nil value

So basically, When I want to execute a code I type it off in this Box and execute it, and later I tried using a function in the code but It gave that response.

Heres how the executor looks.

darock

So the green Play button is server-side execute, and the blue one is client-side.

This is my code I tried in that executor.

local function foo()
       print('Hi')
end

foo()

Green PB Script →

local scriptBoxes = script.Parent.Parent.Parent.ScriptDisplay.ScriptBox.Scripts

local but = script.Parent

local function GetUsingScript()
	for _,ScriptBox in pairs(scriptBoxes:GetChildren()) do
		if ScriptBox:IsA('TextBox') and ScriptBox.Visible == true and string.match(ScriptBox.Name:lower(),'script') then
			return ScriptBox
		end
	end
end

local db = false

local function Execute()
	local Found = GetUsingScript()
	if Found and db == false then
		db = true
		local ScriptThings = Found.Text
		game.ReplicatedStorage.Events.ExecuteScript:FireServer(ScriptThings)
		wait(0.4)
		db = false
	end
end

but.MouseButton1Click:Connect(Execute)

Blue PB Script →

local scriptBoxes = script.Parent.Parent.Parent.ScriptDisplay.ScriptBox.Scripts

local but = script.Parent

local function GetUsingScript()
	for _,ScriptBox in pairs(scriptBoxes:GetChildren()) do
		if ScriptBox:IsA('TextBox') and ScriptBox.Visible == true then
			return ScriptBox
		end
	end
end


local db = false

local function Execute()
	local Found = GetUsingScript()
	if Found and db == false then
		db = true
		local ScriptThings = Found.Text
		require(script.Loadstring)(ScriptThings, getfenv())()
		wait(0.4)
		db = false
	end
end

but.MouseButton1Click:Connect(Execute)

(This is entirely dependant on which loadstring you’re using:)

require(script.Loadstring)(ScriptThings, getfenv())()
The return of loadstring is usually a function if it was successful in compiling.
However, if the loadstring failed, it’ll return nil with an error message instead, like so:

local loadstring = require(script.Loadstring)

local compiled, errorMessage = loadstring(sourceCode)
if compiled then
	compiled()
else
	-- this will most likely happen because of a syntax error
	warn(errorMessage)
end

which one returns the response in the console
the server side or client side

Hey thanks, But I already got it done tho, Yeah its the syntax error, Not the module.