배우기
엔진 데이터 형식
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
-- 인스턴스 이벤트 래퍼: OnTouched는 BasePart.Touched를 래핑합니다.
-- 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

메서드
ForEach
Collection:ForEach(callback:function)
매개 변수
callback:function

Destroy
Collection:Destroy()

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