Script.Source not executing?

I’m trying to create a scripting Lua Plugin but I’m struggling to find a way to execute it


I have tried making a BindableEvent so a script finds the trigger and create a module so it the script changes the source of the module but failed so i tried the method

Here’s the script

--Lua app

local data = {}--Module script

function runScript(typenew,source)--Run Lua app
	if typenew == "Local" then--If player asks for local script
		local newScript = Instance.new("LocalScript",script)
		newScript.Source = source--Changes the scripts source
	end
	
	if typenew == "Server" then--If player asks for ServerScript
		local newScript = Instance.new("Script",script)
		newScript.Source = source--Changes the scripts source
	end
end

function data.new(typenew ,source)--typenew : what kind of script the player wants ,source : script source
	runScript(typenew,source)
end

return data

And also this script only works on plugins or command bar that’s all!

You can use loadstring for this.

local function runScript(source)
    loadstring(source)()
end

local stringToRun = 'print(\'hi\')'

runScript(stringToRun) --> hi
2 Likes

As @7z99 already said, you can use loadstring for the source.

loadstring(yourscript.Source)

Also if it errors, there’s a module for this.

1 Like

That module appears to be offsale.

Oh, my bad. There was a new one.
(3) vLua 5.1 (improved VM) - Roblox

1 Like

Here’s the improved link vLua 5.1 (improved VM) - Roblox

Wow, I had it already. What a coincidence.

I am trying to figure this out the module wants the Source and Env ,

i don’t understand ENV

I don’t know what env is either, but it’s not required.

local loadstring = require(path to module)
loadstring("your code here")
1 Like

That is an environment, it can be gotten via getfenv().

You shouldn’t need environments for executing code. If you want to catch errors, you could use pcall.

local myString = [[
local function errorThread(...) 
    error(...) 
end 
errorThread('cool error message')]] 
local func = loadstring(myString) 
local success, errorMessage = pcall(func) 
print(success, errorMessage)

Also just want to add that loadstring returns a function value which can be called as normal, not a thread or anything.

1 Like