Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.