Skip to content

Documentation: Tags

Egiziano edited this page Jan 7, 2023 · 1 revision

Functions:

FindFirstChildTagged

Summary: Searches for the first child of the given ancestor instance that has a specific tag. It returns the first child that is found with the specified tag, or nil if no such child is found.

Syntax: FindFirstChildTagged(Ancestor: Instance, Tag: (string | {string})) → Instance?

Parameters:
  • Ancestor: The ancestor instance to search for children in.

  • Tag: The tag to search for. This can be a string or an array of strings.

Retruns:
  • Instance?: The first child instance that was found with the specified tag, or nil if no such child was found.

Code Example:
local Ancestor = game:GetService("Workspace")
local Child = Tags.FindFirstChildTagged(Ancestor, "HealPart")
print(Child)

FindFirstDescendantTagged

Summary: Searches for the first child of the provided Ancestor instance that has the specified Tag string or any of the Tag strings in the provided table.

Syntax: FindFirstDescendantTagged(Ancestor: Instance, Tag: (string | {string})) → Instance?

Parameters:
  • Ancestor: An instance representing the object whose children will be searched.

  • Tag: A string or a table of strings representing the tags to search for.

Retruns:
  • Instance?: An instance representing the first child of the Ancestor object that has the specified Tag, or nil if no such child was found.

Code Example:
local Part = workspace:FindFirstChildTagged("Laser")
print(Part)

FindFirstAncestorTagged

Summary: Gets the first ancestor of a given object that is tagged with the specified tag.

Syntax: FindFirstAncestorTagged(Object: Instance, Tag: string) → Instance?

Parameters:
  • Object: The object whose ancestor you want to find.

  • Tag: The tag to search for on the ancestor.

Retruns:
  • Instance?: The first ancestor of Object that is tagged with Tag, or nil if no such ancestor is found.

Code Example:
local Object = game.Workspace.Part
local Ancestor = Tags.GetAncestorTagged(Object, "MyTag")

print(Ancestor) -- Outputs the first ancestor of Object that is tagged with "MyTag", or nil if no such ancestor is found.

GetChildrenTagged

Summary: Returns an array of children of the Ancestor instance that are tagged with Tag.

Syntax: GetChildrenTagged(Ancestor: Instance, Tag: (string | {string})) → {Instance}

Parameters:
  • Ancestor: The parent instance to search for children.

  • Tag: The tag to search for on the children. Can be a string or an array of strings.

Retruns:
  • table: An array of instances that are children of the Ancestor instance and are tagged with Tag.

Code Example:
local TaggedChildren = Tags.GetChildrenTagged(game.Workspace, {"TestTag", "TestTag_2"})
print("Number of tagged parts in workspace:", #TaggedChildren)

GetDescendantsTagged

Summary: Returns an array of descendant objects from a given ancestor object that have a specified tag.

Syntax: GetDescendantsTagged(Ancestor: Instance, Tag: (string | {string})) → {any}

Parameters:
  • Ancestor: The instance object to search for descendant objects within.

  • Tag: The tag or tags to search for. This can be a single string or an array of strings.

Retruns:
  • table: An array of descendant objects that have the specified tag or tags.

Code Example:
local TaggedDescendants = Tags.GetDescendantsTagged(game.Workspace, {"Laser", "Red", "DamagePart"})
for _, Descendant in ipairs(TaggedDescendants) do
	print(Descendant.Name .. " has one of the specified tags.")
end