Working w/ ModuleScripts?

What I would suggest is changing this so it follows an object-oriented structure.

Have a module that takes care of this. Obviously you need a constructor. Think about which arguments will always remain the same each time you call a function (I assume they are the Exterior and Interior, or the ship model as a whole), those will be passed to the constructor. Add the appropriate methods, such as Enable in your example.

The idea is, instead of having to call a function and pass what ship the function will affect, you create an object that keeps a reference to the ship, and calling methods on that object, that way the method knows by itself what ship the function will affect: it’s the ship referenced by the object the method we called is bound (this object is simply self).

Some hypothetical piece of code:

local shipWrapper = require(game.ServerStorage.shipWrapper)

local ship1 = shipWrapper.new(Exterior, Interior) --Exterior and Interior belonging to the ship in question
local ship2 = shipWrapper.bew(Exterior2, Interior2)

ship1:Enable(SomeBodyMovers) --you don't need to pass exterior and interior
ship2:Enable(someBodyMovers2) --the magic happens inside

If you’re not used to or never heard of object oriented style of programming, I suggest this topic.

1 Like