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?
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