# CollectionService

CollectionService : `Instance`

## Overview

인스턴스에 문자열 형태의 태그를 부여하여 유사한 속성을 가진 객체들을 효율적으로 그룹화하고 제어할 수 있도록 지원하는 서비스입니다.

서버에서 지정된 태그는 클라이언트로 자동 동기화되어, 양측에서 동일한 태그 상태를 유지할 수 있습니다.

## Properties

## Methods

### AddTag

대상 인스턴스에 지정한 이름의 태그를 추가합니다.

#### Parameters

| `Instance` instance | 대상 인스턴스입니다.    |
| ------------------- | -------------- |
| `string` tag        | 지정할 태그의 이름입니다. |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

### GetTagged

특정 태그가 설정된 객체들을 반환합니다.

단, 게임의 DataModel 구조 안에 포함되어 있는 객체만을 대상으로 하며, 아직 부모가 지정되지 않았거나 DataModel 구조 외부에 있는 객체는 결과에서 제외됩니다.

#### Parameters

| `string` tag | 조회할 태그의 이름입니다. |
| ------------ | -------------- |

#### Return

| `Array` | 지정된 태그가 적용된 객체들의 배열입니다. |
| ------- | ----------------------- |

#### Code Samples

```lua
local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

CollectionService:AddTag(Part, "SomeTag")
```

### GetTags

대상 인스턴스에 적용된 태그 목록을 문자열 배열로 반환합니다. 특정 태그만 확인하는 HasTag()와 달리, 인스턴스에 적용된 모든 태그를 조회할 때 적합합니다.

#### Parameters

| `Instance` Instance | 대상 인스턴스입니다. |
| ------------------- | ----------- |

#### Return

| `Array` | 문자열로 구성된 배열입니다. |
| ------- | --------------- |

#### Code Samples

```lua
local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

local Tags = CollectionService:GetTags(Part)
print(Tags)
```

### HasTag

대상 인스턴스에 지정한 이름의 태그가 추가되어 있으면 true를 반환합니다.

#### Parameters

| `Instance` instance | 대상 인스턴스입니다.    |
| ------------------- | -------------- |
| `string` tag        | 확인할 태그의 이름입니다. |

#### Return

| `bool` | 태그의 존재 여부입니다. |
| ------ | ------------- |

#### Code Samples

```lua
local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

local hasTag = CollectionService:HasTag(Part, "SomeTag")
print(hasTag)
```

### RemoveTag

대상 인스턴스에 지정한 이름의 태그를 삭제하며, 해당 태그가 존재하지 않아도 오류 없이 동작합니다.

#### Parameters

| `Instance` instance | 대상 인스턴스입니다.    |
| ------------------- | -------------- |
| `string` tag        | 삭제할 태그의 이름입니다. |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

CollectionService:RemoveTag(Part, "SomeTag")
```

## Events


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/korean/development/api-reference/classes/collectionservice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
