Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I destroy excessive cloned parts if cloned parts are more than 1, 2, 5, etc. parts?

Asked by
MrHerkes 166
7 years ago

For example, I want to clone a part every time a character touches a button. There are more than ten parts that are cloned. I want the cloned parts destroyed when parts are more than 5 parts. How do I do that?

1 answer

Log in to vote
2
Answered by
mraznboy1 194
7 years ago

One way to do it would be to store the parts in a table then check how many objects are in that table every time you create a new object.

01local itemTable = {}
02function cloneObject(object)
03    local newObject = object:clone()
04    newObject.Parent = --wherever you need
05    --[[
06    more lines specifying the object, etc
07    --]]
08    table.insert(itemTable, newObject)
09    if (#itemTable > number) then
10        for _, v in ipairs(itemTable) do
11            v:remove() --or however you want to "destroy" the object
12        end
13    end
14end
Ad

Answer this question