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