function placeBrick(C,F,l)local B=Instance.new("\080\097\114\116")B.BrickColor=BrickColor.Random()B.CFrame=C*CFrame.new(F+B.Size/2);(script.Parent.BrickCleanup:Clone()).Parent=B B.BrickCleanup.Disabled=false B.Parent=game.Workspace B:MakeJoints()return B,F+B.Size end function buildWall(C)local F=BrickColor.Random()local l={}assert(wallWidth>0)local B=0 while B<wallHeight do local h local K=-wallWidth/2 while K<wallWidth/2 do local y y,h=placeBrick(C,Vector3.new(K,B,0),F)K=h.x table.insert(l,y)wait(brickSpeed)end B=h.y end return l end function snap(C)if math.abs(C.x)>math.abs(C.z)then if C.x>0 then return Vector3.new(1,0,0)else return Vector3.new(-1,0,0)end else if C.z>0 then return Vector3.new(0,0,1)else return Vector3.new(0,0,-1)end end end Tool.Enabled=true function onActivated()if not Tool.Enabled then return end Tool.Enabled=false local C=Tool.Parent local F=C:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if not F then return end local l=MouseLoc:InvokeClient((game:GetService("\080\108\097\121\101\114\115")):GetPlayerFromCharacter(C))local B=snap((l-C.Head.Position).unit)local h=CFrame.new(l,l+B)Tool.Handle.BuildSound:Play()buildWall(h)wait(5)Tool.Enabled=true end Tool.Activated:Connect(onActivated)

function placeBrick(cf, pos, color)
	local brick = Instance.new("Part")
	brick.BrickColor = BrickColor.Random()
	brick.CFrame = cf * CFrame.new(pos + brick.Size / 2)
	script.Parent.BrickCleanup:Clone().Parent = brick -- attach cleanup script to this brick
	brick.BrickCleanup.Disabled = false
	brick.Parent = game.Workspace
	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

	return bricks

end


function snap(v)
	if math.abs(v.x)>math.abs(v.z) then
		if v.x>0 then
			return Vector3.new(1,0,0)
		else
			return Vector3.new(-1,0,0)
		end
	else
		if v.z>0 then
			return Vector3.new(0,0,1)
		else
			return Vector3.new(0,0,-1)
		end
	end
end


Tool.Enabled = true
function onActivated()

	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent;
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		return 
	end

	local targetPos = MouseLoc:InvokeClient(game:GetService("Players"):GetPlayerFromCharacter(character))
	local lookAt = snap( (targetPos - character.Head.Position).unit )
	local cf = CFrame.new(targetPos, targetPos + lookAt)

	Tool.Handle.BuildSound:Play()

	buildWall(cf)

	wait(5)

	Tool.Enabled = true
end

Tool.Activated:Connect(onActivated)

