# ModuleScript

ModuleScript : `LuaSourceContainer`

## Overview

A ModuleScript is a script instance used to separate common functionalities and structure them for reuse.

It can be loaded using the require() function, returning a single value upon when called. It means, even if multiple scripts in the same execution environment call require() on the same ModuleScript, the module executes only once, and subsequent calls share the initially returned value. By minimizing redundancy and defining functionality in a single location for shared use across different locations, it significantly enhances maintainability and reusability.

In distinct execution environments, such as server and client, a ModuleScript runs independently. For instance, a ModuleScript that has already been executed on the server will be executed again when calling require() on the client.

The require() function typically does not halt execution flow by default. However, if a ModuleScript employs a wait function, such as wait(), the calling thread pauses until the ModuleScript returns a value. As circular references, where ModuleScripts mutually require() each other, can cause threads to freeze, meticulous dependency management is critical in large-scale projects.

A ModuleScript can define properties and functions in a table and return it for external scripts to reference.

External scripts can use the require() function to retrieve this table via ModuleScript, granting access to its defined properties and functions.

## Properties

## Methods

## Events

## See also

{% content-ref url="/pages/e3wO4BcMNkD8WqBXjSNK" %}
[Module Script](/manual/script-manual/advanced-gameplay-systems/modulescript.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/development/api-reference/classes/modulescript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
