Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Documentation: ClearAll

Egiziano edited this page Jan 7, 2023 · 1 revision

Functions:

ClearAllChildrenWhichAre

Summary: This function removes all children of an instance that belong to a specified class.

Syntax: ClearAllChildrenWhichAre(Ancestor: Instance, ClassName: string) → number

Parameters:
  • Ancestor: An instance that represents the parent object from which children will be removed.

  • ClassName: A string that represents the class name of the children that will be removed.

Retruns:
  • number: The total number of instances that has been destroyed.

Code Example:
local Part = Instance.new("Part")
Part.Parent = game.Workspace
Part.Name = "PartA"

local Part = Instance.new("Part")
Part.Parent = game.Workspace
Part.Name = "PartB"

local Cleared = Clear.ClearAllChildrenWhichAre(game.Workspace, "Part")
print(Cleared)  -- Output: 2

ClearAllDescendantsWhichAre

Summary: This function removes all children of an instance that belong to a specified class.

Syntax: ClearAllDescendantsWhichAre(Ancestor: Instance, ClassName: string) → number

Parameters:
  • Ancestor: An instance representing the ancestor object whose descendants are to be cleared.

  • ClassName: A string representing the name of the class that the descendants to be cleared should belong to.

Retruns:
  • number: A number representing the number of descendants that were cleared.

Code Example:
local Part = workspace.Part
local Destroyed = Clear.ClearAllDescendantsWhichAre(Part, "Script")
print(string.format("Cleared %d descendants which are of class 'Script'", Destroyed))

ClearAllChildrenExcept

Summary: Destroys all children of the given ancestor except for those that match certain criteria specified in the Excluded table.

Syntax: ClearAllChildrenExcept(Ancestor: Instance, Excluded: {[string]: any}) → number

Parameters:
  • Ancestor: An instance representing the ancestor object whose children will be destroyed, except for those specified in the Excluded table.

  • Excluded: A table that specifies the children of Ancestor that should be excluded from being destroyed. This table can have three keys:

    • Instances: An array of instance objects or strings representing the names of instances that should not be destroyed.

    • Properties: A table of property-value pairs representing the properties and values that the instances to be preserved must have. If a child’s property matches the given value, then that child will be excluded from being destroyed.

    • IsA: A string representing the class name that the instances to be preserved must be an instance of.

Retruns:
  • number: An integer representing the number of children that were destroyed.

Code Example:
local Excluded = {
    Instances = {Part},
    Properties = {
        Name = "Model"
    },
    IsA = "Model"
}

Clear.ClearAllDescendantsExcept(game.Workspace, Excluded)

--| The above code should destroy all instances in the workspace except any instance that is a 'Part' or having any of the names: 'Part1', 'Part2', 'MyPart' And if it has the property 'Transparency' with the value of 1.

ClearAllDescendantsExcept

Summary: Same as the above function. Destroys all descendants of the given ancestor except the ones specified in the Excluded table. It returns then the number of children that were destroyed.

Syntax: ClearAllDescendantsExcept(Ancestor: Instance, Excluded: {[string]: any}) → number

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

  • Excluded: A table that specifies the children of Ancestor that should be excluded from being destroyed. This table can have three keys:

    • Instances: An array of instance objects or strings representing the names of instances that should not be destroyed.

    • Properties: A table of property-value pairs that an instance must have to be excluded from the destruction process.

    • IsA: A string representing the class name that the instances to be preserved must be an instance of.

Retruns:
  • number: An integer representing how many descendants that were destroyed.

Code Example:
local Part = game.Workspace.Part
local Excluded = {
	Instances = {Part},
	Properties = {
		Name = "Model"
	},
	IsA = "Model"
}

Clear.ClearAllDescendantsExcept(game.Workspace, Excluded)
--| The above code should destroy all descendants of game.Workspace, except for the instance Part and any other instances that have the property Name set to "Model" or belong to the "Model" class.