Destroy

Constructor:

Destroy()

Description

Sets the object properties to nil. Removes all connections and call Destroy for all child nodes. This function is a proper method to deal with the objects that are no longer needed. It is important to dispose needless objects. The objects and connections that are no longer needed will run out of memory and then lead to serious performance problem. Delete them by using this method to avoid repeated use.

Examples

Create an instance object of a part. When this object is hit by the avatar, delete the object.

local temp1 = RWObject.Create("Part") -- create an instance temp1 of Part
temp1.Color = Vector3.New(255,0,0) -- set the color of temp1
temp1.Position = Vector3.New(3,1,3) -- set the coordinates of temp1
temp1.Name = "ttt" -- set the name of temp1
temp1.Anchored = true -- anchor temp1
temp1.Parent = WorkSpace -- set the parent of temp1
function Deltemp() -- define a method of deletion
    temp1:Destroy() -- delete temp1
end
temp1.CollisionEnter:Connect(Deltemp) -- when temp1 is touched, call the method of deletion to delete temp1.