# ScriptとLocalScriptとModuleScriptの違い

> Scriptはサーバー（全員共通の処理）、LocalScriptは各プレイヤーのコンピューター（その人だけの処理）、ModuleScriptは他のスクリプトから読み込む部品です。置く場所によって動くかどうかが決まるので、組み合わせを覚えておくことが大切です。

- URL：https://roblox.minecraft-okinawa.com/basics/script-vs-localscript/
- 更新日：2026-11-13

## 3種類のスクリプト

| 種類 | どこで動く？ | 主な使いどころ | 置く場所の例 |
|---|---|---|---|
| Script | サーバー | ゲームのルール、キルブロック、データの保存 | ServerScriptService、パーツの中 |
| LocalScript | 各プレイヤーのコンピューター（クライアント） | キー入力、カメラ、画面の表示（GUI） | StarterPlayerScripts、StarterGui |
| ModuleScript | 読み込んだ側 | 何度も使う関数やデータをまとめる | ReplicatedStorage、ServerScriptService |

## いちばん多いつまずき：LocalScriptをWorkspaceに置く

LocalScriptは、Workspaceの中に直接置いても動きません。プレイヤーに関係する場所（StarterPlayerScriptsやStarterGuiなど）に置きます。「スクリプトを書いたのに何も起きない」ときは、まず置き場所を確かめましょう。

## 例：Script（サーバー）

（Script／置く場所：パーツの中）

```lua
local part = script.Parent :: BasePart

part.Touched:Connect(function(hit)
	local character = hit.Parent
	if not character then
		return
	end
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end)
```


## 例：LocalScript（クライアント）

（LocalScript／置く場所：StarterPlayerScripts）

```lua
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then
		return
	end
	if input.KeyCode == Enum.KeyCode.E then
		print("Eキーが押された")
	end
end)
```


## 使い分けの考え方

- みんなに関わること（点数、体力、アイテムの付与）はScript
- その人の画面や操作に関わること（キー入力、GUI、カメラ）はLocalScript
- LocalScriptで起きたことをサーバーに伝えたいときは、[RemoteEvent](https://roblox.minecraft-okinawa.com/reference/classes/RemoteEvent/)を使う

## よくある質問

### Q. LocalScriptが動きません。

A. LocalScriptはWorkspaceに直接置くと動きません。StarterPlayerScripts・StarterCharacterScripts・StarterGuiなどに置いてください。

### Q. ScriptとLocalScriptはどう使い分けますか？

A. 全員に関わる処理（ルール・点数・データ保存）はScript、その人の画面や操作に関わる処理（キー入力・GUI・カメラ）はLocalScriptで書きます。

## 出典

- [Roblox Creator Documentation](https://create.roblox.com/docs)

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