Using require() on a Module that was created using Instance.new()

Is it possible to require() a Module script that you used Instance.new() to create? For example,

local BM = Instance.new('ModuleScript')
local BMData = require(BM)
BM.Name = 'BMData'

I tried this approach, and was given an error with the Module not loading. Is this something that’s not possible to do, or is it done differently?

Most likely, it’s because the module script is not returning anything when you create it.

1 Like

Why would you need to require an empty module?

2 Likes

How would I go about making it not empty, in that case. I just assumed that the code was the same as the default ModuleScript code.

You could use Instance:Clone() on another module script maybe?

1 Like

I’m using a ModuleScript to save PlayerData, and am creating a new one for each.

You should consider using object-oriented programming if you are doing that.

a topic that might be helpful: All about Object Oriented Programming

1 Like

The default ModuleScript code can also count as empty; as for your question, there is no way to go about this without using hacky solutions such as plugins, which of course don’t run in any instances other than Studio.

1 Like