Clone (Method): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
m Text replacement - "</code>" to "</SyntaxHighlight>"
m Text replacement - "<SyntaxHighlight code="lua">" to "<syntaxhighlight lang="lua">"
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
{{clear floats}}
{{clear floats}}


{{Example|<code lua>
{{Example|<syntaxhighlight lang="lua">
local Model = Workspace.Model
local Model = Workspace.Model
while true do
while true do
Line 15: Line 15:
     wait(300)
     wait(300)
end
end
</SyntaxHighlight>}}
</syntaxhighlight>}}


==Objects that cannot be cloned==
==Objects that cannot be cloned==
Line 26: Line 26:
{{Example|
{{Example|
This code demonstrates how you can prevent an object from being cloned using the Archivable property:
This code demonstrates how you can prevent an object from being cloned using the Archivable property:
<code lua>local Part = Instance.new('Part', Workspace)
<syntaxhighlight lang="lua">local Part = Instance.new('Part', Workspace)
print(Part) --> Part
print(Part) --> Part
Part.Archivable = false
Part.Archivable = false
print(Part) --> Part
print(Part) --> Part
local newPart = Part:Clone()
local newPart = Part:Clone()
print(newPart) --> nil</SyntaxHighlight>}}
print(newPart) --> nil</syntaxhighlight>}}


[[Category:Methods]]
[[Category:Methods]]

Latest revision as of 06:19, 27 April 2023

Clone( )
Returns Instance
Description: Returns a clone of the object and its children, unless its Archivable property is false. The clone will have the same properties as the original object and the same descendants (except those with an Archivable property set to false). The clone's Parent will be nil.
Member of: Instance


Example
local Model = Workspace.Model
while true do
    local ModelCopy = Model:Clone()
    ModelCopy.Parent = Workspace
    wait(300)
end


Objects that cannot be cloned

When Archivable is set to false on an object, the game sees that as a temporary object that should not be involved in saving, nor cloning. When Clone creates the clone of an object and its descendants, any objects with the Archivable property set to false will not be included in the clone. For example, if a Model contains a Part whose Archivable property is set to false, when the Model is cloned, the clone Model will not contain a clone of the Part.

This means that if Clone is called directly on a non-archivable object, it will return nil.

Several classes of objects, such as Hats, the DataModel and services can never be cloned, and behave in the same way as a non-archivable object.

Example

This code demonstrates how you can prevent an object from being cloned using the Archivable property:

local Part = Instance.new('Part', Workspace)
print(Part) --> Part
Part.Archivable = false
print(Part) --> Part
local newPart = Part:Clone()
print(newPart) --> nil