# task（ロブロックス ライブラリ）

> 待つ・あとで実行する・同時に実行する、といった時間に関わる処理のためのライブラリです。task.wait(1) で1秒待てます。

- URL：https://roblox.minecraft-okinawa.com/reference/libraries/task/
- 公式：https://create.roblox.com/docs/reference/engine/libraries/task

## 使用例：3秒カウントダウン

（Script／置く場所：ServerScriptService）

```lua
local count = 3

while count > 0 do
	print(count)
	count -= 1
	task.wait(1)
end
print("スタート！")
```

## 関数

- `task.spawn(functionOrThread: function | thread, ...: Variant): thread`：関数をすぐに、別の流れ（スレッド）で実行します。
- `task.defer(functionOrThread: function | thread, ...: Variant): thread`：今の処理が終わったあとに関数を実行します。
- `task.delay(duration: number, functionOrThread: function | thread, ...: Variant): thread`：指定した秒数のあとに関数を実行します。
- `task.desynchronize(): ()`：Causes the following code to be run in parallel.
- `task.synchronize(): ()`：Causes the following code to be run in serial.
- `task.wait(duration: number): number`：指定した秒数だけ待ちます。
- `task.cancel(thread: thread): ()`：spawnやdelayで予定した処理を取り消します。

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

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