# CollectionService

CollectionService : `Instance`

## Overview

A service that allows you to assign string-based tags to instances, making it easy to group and manage objects with similar properties.

Tags assigned on the server are automatically synchronized to clients, ensuring both sides maintain the same tag state.

## Properties

## Methods

### AddTag

Adds a tag with the specified name to the target instance.

#### Parameters

| `Instance` instance | The target instance.           |
| ------------------- | ------------------------------ |
| `string` tag        | The name of the tag to assign. |

#### Return

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

#### Code Samples

### GetTagged

Returns objects that have a specific tag assigned. Only objects that are included within the game’s DataModel hierarchy are considered. Objects whose parent has not yet been set, or objects that exist outside of the DataModel structure, are excluded from the results.

#### Parameters

| `string` tag | The name of the tag to search for. |
| ------------ | ---------------------------------- |

#### Return

| `Array` | An array of objects that have the specified tag applied. |
| ------- | -------------------------------------------------------- |

#### Code Samples

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

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

### GetTags

Returns an array of all tags applied to the target instance. Unlike HasTag(), which checks for a specific tag, it is ideal for retrieving all tags applied to an instance.

#### Parameters

| `Instance` Instance | The target instance. |
| ------------------- | -------------------- |

#### Return

| `Array` | An array of strings. |
| ------- | -------------------- |

#### Code Samples

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

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

### HasTag

Returns true if a tag with a specified name is added to target instance.

#### Parameters

| `Instance` instance | The target instance.          |
| ------------------- | ----------------------------- |
| `string` tag        | The name of the tag to check. |

#### Return

| `bool` | Whether the tag exists. |
| ------ | ----------------------- |

#### Code Samples

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

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

### RemoveTag

Removes the tag with the specified name from the target instance, and operates without errors even if the tag does not exist.

#### Parameters

| `Instance` instance | The target instance.           |
| ------------------- | ------------------------------ |
| `string` tag        | The name of the tag to remove. |

#### 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/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.
