学ぶ
エンジンデータ型
Collection

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


概要
プロパティ
方法
ForEach(callback: function)
コードサンプル
コレクションのライフサイクルとイベント
local CollectionService = game:GetService("CollectionService")
-- "MapleLeaf" タグが付けられたパーツのライブコレクションで、モデル "MapleTree" の直接の子です
local mapleLeaves: Collection = CollectionService:CreateCollection("Model.MapleTree > Part.MapleLeaf")
local function sway(leaf: Part, deltaTime: number)
leaf.CFrame *= CFrame.fromEulerAnglesXYZ(0, math.rad(20) * deltaTime, 0)
end
local function fall(leaf: Part)
leaf.Anchored = false
end
-- OnAdded は、すでに一致している葉ごとに一度発火し、その後新しい一致ごとに発火します
function mapleLeaves.OnAdded(leaf: Part)
leaf.Material = Enum.Material.Neon
end
-- OnRemoved は、葉が一致しなくなったとき(タグが外された、木から再親子化された、または破壊されたとき)に発火します
function mapleLeaves.OnRemoved(leaf: Part)
leaf:Destroy()
end
-- RunService エイリアス: コレクション内の各葉に対して、心拍ごとに一度発火します
function mapleLeaves.OnHeartbeat(leaf: Part, deltaTime: number)
sway(leaf, deltaTime)
end
-- Instance-event wrapper: OnTouched は BasePart.Touched をラップします
-- Touched イベントを持たないコレクションメンバーは、この割り当てを静かに無視します
function mapleLeaves.OnTouched(leaf: Part, other: BasePart)
fall(leaf)
end
-- Property-changed wrapper: 葉が茶色になると反応します
function mapleLeaves.OnPropertyChanged.Color(leaf: Part)
if leaf.Color == Color3.fromRGB(124, 92, 70) then
fall(leaf)
end
end
-- 現在コレクションにあるすべての葉を緑に設定します
mapleLeaves:ForEach(function(leaf: Part)
leaf.Color = Color3.fromRGB(0, 255, 0)
end)

APIリファレンス
プロパティ
Enabled
Collection.Enabled:boolean

方法
ForEach
Collection:ForEach(callback:function)
パラメータ
callback:function

Destroy
Collection:Destroy()

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。