function fix(U)U=tostring(U)U=U:reverse()local C=""for y=1,#U,1 do if y%3==0 then C=C..(U:sub(y,y).."\044")else C=C..U:sub(y,y)end end C=C:reverse()if C:sub(1,1)=="\044"then C=C:sub(2)end return C end function count()if active then awaiting=awaiting+1 return end active=true wait()baseParts={}local function U(C)for C,y in pairs(C:GetChildren())do if y:IsA("\066\097\115\101\080\097\114\116")then table.insert(baseParts,y)end if#baseParts%1000==0 and#baseParts~=0 then wait()end U(y)end end U(game.Workspace)local C=#baseParts script.Parent.Count.Text=fix(C)..(C==1 and" \066\114\105\099\107"or" \066\114\105\099\107\115")for U=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()
-- The argument must be an integer:
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()
