function fix(n)n=tostring(n)n=n:reverse()local F=""for C=1,#n,1 do if C%3==0 then F=F..(n:sub(C,C).."\044")else F=F..n:sub(C,C)end end F=F:reverse()if F:sub(1,1)=="\044"then F=F:sub(2)end return F end function count()if active then awaiting=awaiting+1 return end active=true wait()baseParts={}local function n(F)for F,C in pairs(F:GetChildren())do if C:IsA("\066\097\115\101\080\097\114\116")then table.insert(baseParts,C)end if#baseParts%1000==0 and#baseParts~=0 then wait()end n(C)end end n(game.Workspace)local F=#baseParts script.Parent.Count.Text=fix(F)..(F==1 and" \066\114\105\099\107"or" \066\114\105\099\107\115")for n=1,awaiting,1 do count()end awaiting=0 active=false end function setup()count()game.Workspace.DescendantAdded:connect(count)game.Workspace.DescendantRemoving:connect(count)end setup()

function fix(num)
	num = tostring(num)
	num = (num:reverse())
	local newNum = ""
	for i = 1,#num do
		if ((i%3) == 0) then	-- Modulo trick to determine if a number is divisible by 3
			newNum = (newNum .. num:sub(i,i) .. ",")
		else
			newNum = (newNum .. num:sub(i,i))
		end
	end
	newNum = newNum:reverse()
	if (newNum:sub(1,1) == ",") then
		newNum = newNum:sub(2)	-- Quick-fix to correct a mistake in the loop above
	end
	return newNum	-- Returns a string, NOT a number!
end

function count()
	if (active) then
		awaiting = (awaiting+1)
		return
	end
	active = true
	wait()	-- When using 'DescendantRemoving,' the brick removing isn't always gone by the time the function is called, so this gives it some time to be removed
	baseParts = {}	-- Clear table
	local function scan(parent)
		for _,v in pairs(parent:GetChildren()) do	-- Easiest way to get all parts is to quickly scan through with loops
			if (v:IsA("BasePart")) then
				table.insert(baseParts,v)
			end
			if (((#baseParts%1000) == 0) and (#baseParts ~= 0)) then	-- Add in a quick wait every 1k bricks to stop an unneccessary lag-attack
				wait()
			end
			scan(v)
		end
	end
	scan(game.Workspace)
	local n = #baseParts
	script.Parent.Count.Text = (fix(n) .. (n == 1 and " Brick" or " Bricks"))	-- Not many people realize what you can do with 'and' and 'or'
	for i = 1,awaiting do
		count()
	end
	awaiting = 0
	active = false
end

function setup()	-- Yes, I add pointless functions to capture events. It feels more organized
	count()
	game.Workspace.DescendantAdded:connect(count)
	game.Workspace.DescendantRemoving:connect(count)
end

setup()
