More efficient way to require modules?

I am not currently experiencing a problem I have with a server Modulescript intended to be required to apply a cooldown to all server requests, but I’m simply wondering if it’s possible to require a module from perhaps, 50+ parts in my place’s workspace more efficiently/quickly than having to type out the entire (require) declaration at the start of each object’s script?

This is just for sake of organization.

Not that it’s absolutely staple, but I’m just wondering if there’s some sort of loop/table I can create that sets up module connections easily to each of my objects? So that I wouldn’t need 50 individual scripts?

It’s better to have one single Script or ModuleScript managing all parts of a single kind. You could use CollectionService to identify Instances you want to do something for.

Alternatively you could use shared / _G, or linked source scripts.

1 Like

Linked source scripts are not a great idea. They have a multitude of issues with them and are not very portable.

To answer OP’s question, you could look into a “module loader”; that is, a framework that will load your modules for you to allow for easier code communication and management.
Quenty’s nevermore is a good example of this.

5 Likes

Ah, CollectionService, (New to me D:) would this mean I’d have to make use of metatables? From what I know, (I haven’t touched metatables yet or global variables) I pick up on stuff quickly - maybe you could give me like a very short explanation/wiki source?

1 Like

I see, I’ve heard about frameworks (Like Aero and the one you mentioned), and I guess I’ll look into module loaders. Thanks to you both anyhow. :slight_smile:

1 Like

CollectionService lets you attach tags to Instances, no metatables involved. So you can use a plugin to tag all the doors with “Door”. Then in a master door script, control all doors.

1 Like

Omg! That’s wonderful! I am reading on CollectionService page right now, and as you and both the wiki put it, it makes everything far more… clean and straightforward.

Fun fact - Before you told me about this service I actually was kind of using my own “makeshift” CollectionService - The tags the service can apply for me were instead StringValues and then I used a very (bulky, yikes, loop)

I’m converting my old system to Collection right now. :smiley:

Extra
Ps. I read this on the wiki, and I could be wrong but - does the way the replication works as stated mean… you can tag a Player’s character and then monitor humanoid changes on their client? :open_mouth: (Sorry, getting my hopes up.)

More than that. They’ve been completely sunset.

2 Likes

Yeah I forgot about that, haha.

1 Like