function placeBrick(k,w,u)local R=Instance.new("\080\097\114\116")R.BrickColor=u R.CFrame=k*CFrame.new(w+R.size/2)R.Parent=script.Parent.Bricks R:makeJoints()return R,w+R.size end function buildWall(k)local w=BrickColor.random()local u={}assert(wallWidth>0)local R=0 while R<wallHeight do local y local r=-wallWidth/2 while r<wallWidth/2 do local l l,y=placeBrick(k,Vector3.new(r,R,0),w)r=y.x table.insert(u,l)wait(brickSpeed)end R=y.y end wait(wallLifetime)while#u>0 do(table.remove(u)):Remove()task.wait(brickSpeed/2)end end script.Parent.ChildAdded:connect(function(k)if k.Name=="\078\101\119\087\097\108\108"then k:remove()buildWall(k.Value)end end)
-- places a brick at pos and returns the position of the brick's opposite corner
function placeBrick(cf, pos, color)
	local brick = Instance.new("Part")
	brick.BrickColor = color
	brick.CFrame = cf * CFrame.new(pos + brick.size / 2)
	brick.Parent = script.Parent.Bricks
	brick:makeJoints()
	return brick, pos + brick.size
end

function buildWall(cf)
	local color = BrickColor.random()
	local bricks = {}

	assert(wallWidth > 0)
	local y = 0
	while y < wallHeight do
		local p
		local x = -wallWidth / 2
		while x < wallWidth / 2 do
			local brick
			brick, p = placeBrick(cf, Vector3.new(x, y, 0), color)
			x = p.x
			table.insert(bricks, brick)
			wait(brickSpeed)
		end
		y = p.y
	end

	wait(wallLifetime)

	-- now delete them!
	while #bricks > 0 do
		table.remove(bricks):Remove()
		task.wait(brickSpeed / 2)
	end
end

script.Parent.ChildAdded:connect(function(item)
	if item.Name == "NewWall" then
		item:remove()
		buildWall(item.Value)
	end
end)
