Max Parts in a folder Script

Hello, I am trying to figure out how to script when a folder has max parts it will stop , anyone got any ideas?


You can get the number of instances in a folder by getting the length of its children:

local instances = #folder:GetChildren()

With # you can get the length of a table since GetChildren() returns a table.

Otherwise if there are parts and models in the folder and you only want to get the number of parts you can filter them using the IsA() function.

local partsCount = 0

for instance, index in pairs(folder:GetChildren()) do
    if instance:IsA("Part") then
        partsCount += 1 -- Add 1 to the parts count

Heres my Example Script.

local folder ='Folder')
folder.Name = 'folderParts'
folder.Parent = workspace

local maxparts = 40
local parts = 0

	parts = parts - 1

while true do
	if parts < maxparts then
		parts = parts + 1
		local part ='Part')
		part.Parent = folder
		part.Position =,20,20)
		game:GetService('Debris'):AddItem(part, 10)

Note: Script can be inaccurate or what so, just make that script as example.

You could make it so before adding a part to the folder you check if it already has the maximum amount of parts, and if it is, you just use the return keyword

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.