--Loop For Making Rays For The Bullet's Trajectory
for i = 1, 30 do
	local thisOffset = offset + Vector3.new(0, yOffset*(i-1), 0)
	local travelRay = Ray.new(point1,thisOffset)
	local hit, position = workspace:FindPartOnRay(travelRay, parts.Parent)

	local distance 		= (position - point1).magnitude
	round.Size				= Vector3.new(.6, distance, .6)
	round.CFrame			= CFrame.new(position, point1)
								* CFrame.new(0, 0, -distance/2)
								* CFrame.Angles(math.rad(90),0,0)
	round.Parent			= workspace
	point1					= point1 + thisOffset
	
	

	if hit then
		round:remove()
		local e = Instance.new("Explosion")
		e.BlastRadius = 5
		e.BlastPressure = 0
		e.Position = position
		e.Parent = workspace
		e.DestroyJointRadiusPercent = 0
		
		

			if hit and hit.Parent then
		if hit.Parent:FindFirstChild("Humanoid") then
			return hit.Parent.Humanoid
		elseif hit.Parent.Parent:FindFirstChild("Humanoid") then
			return hit.Parent.Parent.Humanoid
		
		elseif (hit.Parent.Name ==  "Hull") or (hit.Parent.Name ==  "Turret") or (hit.Parent.Name ==  "Gun") or (hit.Parent.Name ==  "Parts") then
			print("You Have Damaged a Vehicle")
			local HitSound = hit.Parent:findFirstChild("Pen"):Clone()
			HitSound.Parent = hit
			HitSound:Play()
			hit.Parent.Parent:findFirstChild("Damage").Value = hit.Parent.Parent:findFirstChild("Damage").Value - dealingdamage
			if hit.Parent.Parent:findFirstChild("Damage").Value<1 and hit.Parent.Parent:findFirstChild("Destroyed").Value == false then
				
			local DestroyScript = hit.Parent.Parent:findFirstChild("DestroyScript"):clone()
			DestroyScript.Parent = hit.Parent.Parent
			DestroyScript.Disabled = false		
		
			print("Vehicle Disabled")
		
		
			end

		elseif hit.Name == "Left Arm" or hit.Name == "Left Leg" or hit.Name == "Right Arm" or hit.Name == "Right Leg" or hit.Name == "Torso" or hit.Name == "HumanoidRootPart" then
			hit.Parent:findFirstChild("Humanoid").Health = hit.Parent:findFirstChild("Humanoid").Health - dealingdamage
			print("Direct Hit a Player lmao")
			
		elseif hit.Parent.Name == "Face" then
			hit.Parent.Parent:findFirstChild("Humanoid").Health = hit.Parent.Parent:findFirstChild("Humanoid").Health - dealingdamage
			print("Direct Hit a Morph of a Player lmao")
		elseif (hit.Parent.Name ==  "Full") or (hit.Parent.Name ==  "Damage") then
            hit.Parent.Parent:FindFirstChild("Stats").Health.Value = hit.Parent.Parent:FindFirstChild("Stats").Health.Value - 1	
				
			
		end
		end

		

		local players = game.Players:getChildren()
		for i = 1, #players do
		
			
			-- if players[i].TeamColor ~= script.Parent.Parent.Tank.Value then --if he's not an ally
				character = players[i].Character
				torso = character:findFirstChild'Torso'
				if character and torso then
						
						torsoPos = torso.Position
						origPos = round.Position
						
						local ray = Ray.new(origPos, torsoPos-origPos)
						local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignoreList)
						if hit then
							if hit.Parent == character then
								human = hit.Parent:findFirstChild("Humanoid")
								human2 = hit.Parent.Parent:findFirstChild("Humanoid")
								if human then
									distance = (position-origPos).magnitude