--for _, item in ipairs(Shield:GetChildren()) do
--	if item:IsA("BasePart") == true and item:FindFirstChild("Ignore") == nil then
--		item.Touched:connect(function(Hit)
--			if Hit == nil then return end
--			if Hit.Parent == nil then return end
--			
--			local Item = Hit.Parent
--			
--			if Item:IsA("Tool") == true then return end
--			if Hit.Name == "Torso" then return end
--			if Hit.Name == "HumanoidRootPart" then return end
--			if Hit.Name == "Left Leg" then return end
--			if Hit.Name == "Right Leg" then return end
--			if Hit.Name == "Head" then return end
--			if Hit.Name == "Left Arm" then return end
--			if Hit.Name == "Right Arm" then return end
--			
--			if Game:GetService("Players"):GetPlayerFromCharacter(Item) ~= nil then return end
--			
--			for _, x in ipairs(Hit:GetChildren()) do
--				if x:IsA("TouchTransmitter") == true then x:Destroy() break end
--			end
--			
--			if Item.Name == "ShadowGrab" then
--				Health = Health - (MaxHealth / 12)
--				
--				HealthBar.Shield.Bar:TweenSize(UDim2.new((Health / MaxHealth), 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.5, true)									
--				
--				Item:Destroy()
--				
--				if Health > 0 then
--					-- yay, still alive.
--				else
--					HealthBar.Parent.Parent:Destroy()
--				end
--			end
--		end)
--	end
--end


function CreateRegion3FromLocAndSize(Position, Size)
	local SizeOffset = Size / 2
	local Point1 = Position - SizeOffset
	local Point2 = Position + SizeOffset
	return Region3.new(Point1, Point2)
end

function FindNear(part, radius)
	local r = CreateRegion3FromLocAndSize(part.Position, Vector3.new(part.Size.X + radius, 50, part.Size.Z + radius))
	
	return Game:GetService("Workspace"):FindPartsInRegion3(r, part, 100)
end

while true do
	for _, x in ipairs(Shield:GetChildren()) do
		if x:IsA("BasePart") == true and x.Name ~= "Overhead" and x:FindFirstChild("Ignore") == nil then
			for _, item in ipairs(FindNear(x, 15)) do
				if item:IsA("BasePart") == true then
					local own, dmg = GetOwnerAndDamage(item)
					
					if own ~= nil and dmg ~= nil and item:FindFirstChild("Pierce") == nil then
						if (item.Position - x.Position).magnitude <= 15 and item ~= x then
							if Health > 0 then
								if Health >= dmg then
									Health = Health - dmg
									
									HealthBar.Shield.Bar:TweenSize(UDim2.new((Health / MaxHealth), 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.5, true)
									
									for _, b in ipairs(item:GetChildren()) do
										if b:IsA("TouchTransmitter") == true then b:Destroy() end
									end
									
									item:Destroy()
									
									if Health > 0 then
										-- yay, still alive.
									else
										HealthBar.Parent.Parent:Destroy()
									end
								else
									HealthBar.Parent.Parent:Destroy()
								end
							else
								HealthBar.Parent.Parent:Destroy()
							end
						end
					end
				end
			end
	
		end
	end
	
	Game:GetService("RunService").Stepped:wait()
end
