Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What do Module Scripts do?

Asked by 9 years ago

Can someone explain the uses and a example script? Thanks! ( the script icon looks like a normal script with a part beside it )

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

ModuleScripts are used to extract and isolate repeatedly used sections of code, the aim of which is to reduce server load when applicable, and to reduce the code you have to edit when you want to change something.

The way they work is, for the Server and each Client, when first requireed, the ModuleScript will run once like a normal Script running, and then return a Table. On subsequent requires, the table returned the first time is returned again. The contents of this table can be anything, and is most typically a list of functions that you are intending to share between your objects.

This allows you to create 'Modules' (hence the name) that your Scripts and LocalScripts can use.

For example, if I wanted to give something Health and a Healthbar, I could give them a Health Module, which would have functions for damaging, healing, and showing/hiding the HP bar. If I wanted them to have AI, I could give them an EnemyAi Module, which in turn could require additional modules based on the actions you need to have it do.

Ad

Answer this question