# ModuleScript（ロブロックス クラス）

> 他のスクリプトから読み込んで使う「部品」のスクリプトです。何度も使う関数やデータをまとめておき、require()で読み込みます。

- URL：https://roblox.minecraft-okinawa.com/reference/classes/ModuleScript/
- 公式：https://create.roblox.com/docs/reference/engine/classes/ModuleScript
- 受け継いでいるクラス：LuaSourceContainer

## 使用例：モジュールを作る

（ModuleScript／置く場所：ReplicatedStorage（名前をMathUtilsにする））

```lua
local MathUtils = {}

function MathUtils.double(n: number): number
	return n * 2
end

return MathUtils
```

## 使用例：モジュールを読み込んで使う

（Script／置く場所：ServerScriptService）

```lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MathUtils = require(ReplicatedStorage:WaitForChild("MathUtils"))

print(MathUtils.double(21))
```

## プロパティ

- `ModuleScript.Source: ProtectedString`：The code to be executed.

英語の説明とメンバー一覧：Roblox Creator Documentation（CC BY 4.0）。日本語の解説はこのサイト独自のものです。

執筆：鈴木孝昌（現役プロジェクトマネージャー／プログラミング講師）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）