배우기
엔진 데이터 형식
Collection

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.


코드 샘플
컬렉션 생명주기 및 이벤트
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.Material = Enum.Material.Plastic
end
-- RunService 콜백: 컬렉션의 각 리프에 대해 매 심장 박동마다 한 번 발생합니다.
function mapleLeaves.OnHeartbeat(leaf: Part, deltaTime: number)
sway(leaf, deltaTime)
end
-- 이벤트 콜백: 각 리프의 BasePart.Touched에 연결됩니다.
function mapleLeaves.OnTouched(leaf: Part, other: BasePart)
fall(leaf)
end
-- 속성 콜백: 리프의 색상이 변경될 때 발생합니다.
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

Query
Collection.Query:string

Root
Collection.Root:Instance

메서드
Destroy
Collection:Destroy()

ForEach
Collection:ForEach(callback:function)
매개 변수
callback:function

GetCount
Collection:GetCount():number
반환

©2026 Roblox Corporation. Roblox 및 Roblox 로고, 'Powering Imagination'은 미국 및 기타 국가 내 당사의 등록 및 미등록 상표입니다.