ScriptとLocalScriptとModuleScriptの違い
入門スクリプト更新日:2026年11月13日Luauの型チェック済み
ひとことで言うと
Scriptはサーバー(全員共通の処理)、LocalScriptは各プレイヤーのコンピューター(その人だけの処理)、ModuleScriptは他のスクリプトから読み込む部品です。置く場所によって動くかどうかが決まるので、組み合わせを覚えておくことが大切です。
この記事で使うAPI
3種類のスクリプト
| 種類 | どこで動く? | 主な使いどころ | 置く場所の例 |
|---|---|---|---|
| Script | サーバー | ゲームのルール、キルブロック、データの保存 | ServerScriptService、パーツの中 |
| LocalScript | 各プレイヤーのコンピューター(クライアント) | キー入力、カメラ、画面の表示(GUI) | StarterPlayerScripts、StarterGui |
| ModuleScript | 読み込んだ側 | 何度も使う関数やデータをまとめる | ReplicatedStorage、ServerScriptService |
いちばん多いつまずき:LocalScriptをWorkspaceに置く
LocalScriptは、Workspaceの中に直接置いても動きません。プレイヤーに関係する場所(StarterPlayerScriptsやStarterGuiなど)に置きます。「スクリプトを書いたのに何も起きない」ときは、まず置き場所を確かめましょう。
例:Script(サーバー)
(Script/置く場所:パーツの中)
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)
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を使う
よくある質問
Q. LocalScriptが動きません。
A. LocalScriptはWorkspaceに直接置くと動きません。StarterPlayerScripts・StarterCharacterScripts・StarterGuiなどに置いてください。
Q. ScriptとLocalScriptはどう使い分けますか?
A. 全員に関わる処理(ルール・点数・データ保存)はScript、その人の画面や操作に関わる処理(キー入力・GUI・カメラ)はLocalScriptで書きます。