-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation: Clone
Summary: This function clones an instance Object
and reparents the cloned instance to a given parent Parent
, or to the same parent as the original object if no parent is specified. The number of clones to create can be specified with the optional argument Clones
.
Syntax: CloneAndParent(Object: Instance, Parent: Instance?, Clones: number?) → (Instance | {Instance})
-
Object
: The instance to be cloned. -
Parent
(Optional): The parent to reparent the cloned instance to. If not specified, the cloned instance will be parented to the same parent as the original object. -
Clones
(Optional): The number of clones to create. If not specified, the function will create 1 clone.
-
Instance
|table
: IfClones
is 1, the function returns the single cloned instance. IfClones
is greater than 1, the function returns an array of the cloned instances.
local Original = game.Workspace.Part
local Clones = Clone.CloneAndParent(Original, game.Workspace, 3)
for _, Clone in ipairs(Clones) do
print(Clone.Name)
end
Summary: This function creates a copy of an instance, but with no children and parents the copy to the original source or to the given parent.
Syntax: CloneWithoutChildren(Object: Instance, Parent: Instance?) → (Instance | {Instance})
-
Object
: The instance to be cloned. -
Parent
(Optional): The parent of the cloned instance. If not specified, the parent ofObject
is used.
-
Instance
: The cloned instance.
local Model = workspace.Model
local ClonedModel = Clone.CloneWithoutChildren(Model)
local ClonedModel_2 = Clone.CloneWithoutChildren(Model, game.ReplicatedStorage)
Summary: Creates a clone of an object and applies the given properties to each of the clones.
Syntax: CloneWithProperties(Object: Instance, Properties: {[string]: any}, Clones: number?) → (Instance | {Instance})
-
Object
: The object to be cloned. -
Properties
: A table of properties (property-value pairs) to be applied to the clones. -
Clones
(Optional): The number of clones to create. If not provided, a default value of 1 will be used.
-
Instance
|table
: If Clones is greater than 1, the function returns a table of the cloned objects. Otherwise, it returns the cloned object.
local OriginalObject = script.Parent
local Properties = {
Parent = game.Workspace,
Name = "New Name"
}
local Clones = Clone.CloneWithProperties(OriginalObject, Properties, 3)
Summary: Creates a number of clones of the given object, and assigns each clone as a child of one of the instances in the given array.
Syntax: CloneToMultiple(Object: Instance, To: {Instance}, ClonesForEachInstance: number?) → ()
-
Object
: The object to be cloned. -
To
: An array of instances to which the clones will be parented. -
ClonesForEachInstance
(Optional): The number of clones that will be created for each instance in theTo
array. This argument is optional, and if not provided, a default value of 1 will be used.
-
table
: An array containing all of the newly created clones.
local Players = game:GetService("Players"):GetPlayers()
local Stats = game:GetService("ServerStorage").Stats
local Clones = Clone.CloneToMultiple(Stats, Players, 2)
--| The above code will create two clones of Stats and assign each clone as a child of every player. The Clones array will contain all of made clones.