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
6 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
6 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.

local itemTable = {}
function cloneObject(object)
    local newObject = object:clone()
    newObject.Parent = --wherever you need 
    --[[
    more lines specifying the object, etc
    --]]
    table.insert(itemTable, newObject)
    if (#itemTable > number) then
        for _, v in ipairs(itemTable) do
            v:remove() --or however you want to "destroy" the object
        end
    end
end
Ad

Answer this question