function placeBrick(t,P)local W=Instance.new("\080\097\114\116")W.Size=Vector3.new(brickWidth,brickHeight,brickDepth)W.BrickColor=colors[math.random(1,#colors)]W.Friction=.01 W.CFrame=t*CFrame.new(P+W.size/2)if math.random()>.5 then W.Material=Enum.Material.Ice else W.Transparency=.1+math.random(1,4)/10 end W.Parent=game.Workspace W:makeJoints()return W,P+W.size end function buildWall(t)local P={}assert(wallWidth>0)local W=0 while W<wallHeight do local Y local b=-wallWidth/2 while b<wallWidth/2 do local i i,Y=placeBrick(t,Vector3.new(b,W,0),color)b=Y.x table.insert(P,i)wait(brickSpeed)end W=Y.y end return P end function snap(t)if math.abs(t.x)>math.abs(t.z)then if t.x>0 then return Vector3.new(1,0,0)else return Vector3.new(-1,0,0)end else if t.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 t=Tool.Parent local P=t.Humanoid if P==nil then print("\072\117\109\097\110\111\105\100 \110\111\116 \102\111\117\110\100")return end local W=P.TargetPoint local Y=snap((W-t.Head.Position).unit)local b=CFrame.new(W,W+Y)if(W-t.Torso.Position).magnitude<64 then staffOut()Tool.Handle.UseSound:Play()buildWall(b)staffUp()wait(5)end Tool.Enabled=true end script.Parent.Activated:connect(onActivated)

function placeBrick(cf, pos)
	local brick = Instance.new("Part")
	brick.Size = Vector3.new(brickWidth, brickHeight, brickDepth)
	brick.BrickColor = colors[math.random(1, #colors)]
	brick.Friction = .01
	brick.CFrame = cf * CFrame.new(pos + brick.size / 2)

	if ( math.random() > .5) then
		brick.Material = Enum.Material.Ice
	else
		brick.Transparency = .1 + (math.random(1,4) / 10)
	end

	brick.Parent = game.Workspace
	brick:makeJoints()
	return  brick, pos +  brick.size
end

function buildWall(cf)

	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.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return 
	end

	local targetPos = humanoid.TargetPoint
	local lookAt = snap( (targetPos - character.Head.Position).unit )
	local cf = CFrame.new(targetPos, targetPos + lookAt)

	if (targetPos - character.Torso.Position).magnitude < 64 then
		staffOut()
		Tool.Handle.UseSound:Play()
		buildWall(cf)
		staffUp()
		wait(5)
	end

	Tool.Enabled = true
end

script.Parent.Activated:connect(onActivated)

