Make loadstring only run code from a module script

Hello devform, in the past I have expermited with loadstrings and one of the conserns that crossed my mind is that it can run any code given to it. I plan on implementing loadstring into a side project that I am working on but I can’t figure out how to make it only run module script code

Ps. Currently on my phone Soo sorry if this doesn’t make sense

What exactly do you mean by “modulescript code”? Do you want the code to return a value like how a modulescript would? loadstring returns a function, which when ran, acts like a function. If the code returns something, it acts like a modulescript.

local code = [[
	local module = {}
	module.foo = function()
		return 'abc'
	end
	return module
]]

local module = loadstring(code)()
print(module.foo())
2 Likes

What I mean my module script code is that it uses a module script provide to it kind of like an API