Is there a way to make variables and paths from completely out of nowhere using a ModuleScript by simply requiring one?
Here’s an example:
return { -- ModuleScript
duna = 1,
}
A script will require it and print the written variable:
local t = require(script.ModuleScript) -- Script
print(duna) -- 1
I saw something like this in a script called EzConvert (which since I actually worked on MainModules I found that script alot in scripts) that rewrote entirely new paths in normal Scripts
If there is a way or alternative, please post here
Any help is appreciated!
I don’t think you can do that, The only thing that works with this is creating & exporting custom types via ModuleScripts (Technically it isn’t the same thing, You need to call the Module variable and then the Type):
-- Module
export type SomeType = {X: number; Y: number}
export type OtherType = string | number | boolean
return {} -- Could also be `nil`
-- Script
local TypeDefinitions = require(PathToModule)
local SomeTable: TypeDefinitions.SomeType = {
X = 1;
Y = 2;
}
Yeah, this is possible, but it would require using legacy globals from lua.
You’d have to inject the globals into the environment calling the specific module…
-- Module Script
local Module = setmetatable({}, { __index = getfenv() });
Module.duna = 1
return function()
setfenv(2, Module)
end