Clone (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mr Doom Bringer
m Clone moved to Clone (Function)
>Mr Doom Bringer
No edit summary
Line 1: Line 1:
{{CatUp|:Category:Functions}}
The Clone function creates a duplicate of an object. You have to define
{{Function|
{{Function|
name                  = Clone
name                  = Clone
Line 9: Line 13:


==Example==
==Example==
This example creates a copy of a car every 5 minutes, and gives the new car a silly name.
<pre>
<pre>
while true do  --Starts up a While loop
while true do  --Starts up a While loop


  model = game.Workspace.Model:clone() --Right here, it creates a copy of game.Workspace.Model, and sets it as the variable "model"
    model = game.Workspace.Car:Clone()   --This line creates a copy of "Car" in the Workspace, and sets it to the variable "model"
                                          --Since we set it to "model" we can do things with it. For example,


  game.Workspace.Model.Parent = nil  --This sets the game.Workspace.Model's parent to nothing, removing it from the game.
    model.Name = "LOLZCARLOLOLOLOL"      --Here we set the name of the Model to something silly.
                                          --But the model is just a variable, it doesn't exist in the 3D world.  
                                          --For that we need to set it's parent.  


  model.Parent = game.Workspace --Sets the cloned object's Parent to the Workspace.
    model.Parent = game.Workspace         --With this line the part will now appear in the game world.


  wait(300) --Waits for 300 seconds.
    wait(300)                             --Wait 300 seconds, or about 5 minutes.


end
end
</pre>
</pre>

Revision as of 19:15, 25 March 2010

[[::Category:Functions|Up one category:
:Category:Functions]]

The Clone function creates a duplicate of an object. You have to define

Clone( )
Returns Instance object
Description: Returns a copy of this Object and all its children. The copy's Parent is nil


Example

This example creates a copy of a car every 5 minutes, and gives the new car a silly name.

while true do   --Starts up a While loop

     model = game.Workspace.Car:Clone()    --This line creates a copy of "Car" in the Workspace, and sets it to the variable "model"
                                           --Since we set it to "model" we can do things with it. For example,

     model.Name = "LOLZCARLOLOLOLOL"       --Here we set the name of the Model to something silly.
                                           --But the model is just a variable, it doesn't exist in the 3D world. 
                                           --For that we need to set it's parent. 

     model.Parent = game.Workspace         --With this line the part will now appear in the game world.

     wait(300)                             --Wait 300 seconds, or about 5 minutes.

end