local function a(a)local s=tool.Bullet:Clone()table.insert(ignoreTable,s)s.Parent=workspace s.CFrame=CFrame.new(muzzle.CFrame.p,a)s.Trail.Enabled=true wait()s.Transparency=0 local z=false for a=1,numSegments,1 do if not z then local a=(s.CFrame*CFrame.new(0,0,-segmentLength))*CFrame.Angles(dropAngle,0,0)local i=Ray.new(s.Position,(a.p-s.Position).unit*segmentLength)local O,j,m,R=workspace:FindPartOnRayWithIgnoreList(i,ignoreTable)if O and O.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then z=true s.HitSound:Play()hitEvent:FireClient(game.Players:GetPlayerFromCharacter(tool.Parent))local i=O.Parent.Humanoid if O.Name=="\072\101\097\100"and configs.headshotInstaKill==true then local a=O.Parent:FindFirstChild("\078\101\099\107",true)a:Destroy()elseif O.Name=="\072\101\097\100"then i:TakeDamage(headDamage)elseif O.Name=="\084\111\114\115\111"or O.Name=="\085\112\112\101\114\084\111\114\115\111"or O.Name=="\076\111\119\101\114\084\111\114\115\111"then i:TakeDamage(torsoDamage)else i:TakeDamage(otherDamage)end s.CFrame=CFrame.new(j,a.p)local m=Instance.new("\087\101\108\100",s)m.C0=s.CFrame:inverse()*O.CFrame m.Part0=s m.Part1=O s.Anchored=false s.Transparency=1 if configs.blood==true then s.EffectAttachment.BloodEmitter:Emit(20)end wait(1)for a,z in pairs(ignoreTable)do if z==s then table.remove(ignoreTable,a)end end s:Destroy()elseif O then z=true s.CFrame=CFrame.new(j,a.p)s.Transparency=1 s.ThudSound:Play()if hitParticles and(O.Transparency and O.Transparency<1)then if O.ClassName~="\084\101\114\114\097\105\110"then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(O.Color)elseif R==Enum.Material.Grass or R==Enum.Material.LeafyGrass or R==Enum.Material.Ground or R==Enum.Material.Mud or R==Enum.Material.Cobblestone then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.23921568627451,.2,.17254901960784))elseif R==Enum.Material.Asphalt or R==Enum.Material.Concrete or R==Enum.Material.Pavement or R==Enum.Material.Slate then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.3921568627451,.38823529411765,.36470588235294))elseif R==Enum.Material.Limestone or R==Enum.Material.Sand or R==Enum.Material.WoodPlanks then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.67450980392157,.6,.45490196078431))elseif R==Enum.Material.Brick or R==Enum.Material.Sandstone then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.64705882352941,.44705882352941,.37254901960784))elseif R==Enum.Material.Rock then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.36470588235294,.37647058823529,.40392156862745))elseif R==Enum.Material.Basalt or R==Enum.Material.CrackedLava then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.086274509803922,.043137254901961,.03921568627451))elseif R==Enum.Material.Salt or R==Enum.Material.Snow then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.74509803921569,.70588235294118,.74509803921569))elseif R==Enum.Material.Glacier or R==Enum.Material.Ice then s.EffectAttachment.DebrisEmitter.Color=ColorSequence.new(Color3.new(.63529411764706,.76078431372549,.85098039215686))end s.EffectAttachment.DebrisEmitter:Emit(10)end wait(1)for a,z in pairs(ignoreTable)do if z==s then table.remove(ignoreTable,a)end end s:Destroy()else s.CFrame=a end wait(waitBetweenSegments)end end return end

local function createBullet(target)

	-- Crate bullet that uses a trail effect for the trail
	local bullet = tool.Bullet:Clone()
	table.insert(ignoreTable, bullet)
	bullet.Parent = workspace
	bullet.CFrame = CFrame.new(muzzle.CFrame.p, target)
	bullet.Trail.Enabled = true
	wait() -- so trail has time to load

	bullet.Transparency = 0
	local missionAccomplished = false

	for i = 1, numSegments do
		if not missionAccomplished then
			local equation  = bullet.CFrame * CFrame.new(0, 0, -segmentLength) * CFrame.Angles(dropAngle, 0, 0)
			local ray = Ray.new(bullet.Position, (equation.p - bullet.Position).unit * segmentLength)
			local part, pos, normal, material = workspace:FindPartOnRayWithIgnoreList(ray, ignoreTable)
			if part and part.Parent:FindFirstChild("Humanoid") then
				missionAccomplished = true
				bullet.HitSound:Play()
				hitEvent:FireClient(game.Players:GetPlayerFromCharacter(tool.Parent))
				local hum = part.Parent.Humanoid
				if part.Name == "Head" and configs.headshotInstaKill == true then
					local neck = part.Parent:FindFirstChild("Neck", true)
					neck:Destroy()
				elseif  part.Name == "Head" then
					hum:TakeDamage(headDamage)
				elseif part.Name == "Torso" or part.Name == "UpperTorso" or part.Name == "LowerTorso" then -- Names to account for R6 and R15
					hum:TakeDamage(torsoDamage)
				else
					hum:TakeDamage(otherDamage)
				end


				bullet.CFrame = CFrame.new(pos, equation.p)
				local weld = Instance.new("Weld", bullet)
				weld.C0 = bullet.CFrame:inverse() * part.CFrame
				weld.Part0 = bullet
				weld.Part1 = part
				bullet.Anchored = false
				--bullet.Trail.Enabled = false
				bullet.Transparency = 1
				if configs.blood == true then
					bullet.EffectAttachment.BloodEmitter:Emit(20)
				end
				wait(1)
				for ii, v in pairs(ignoreTable) do
					if v == bullet then
						table.remove(ignoreTable, ii)
					end
				end
				bullet:Destroy()
			elseif part then
				missionAccomplished = true
				bullet.CFrame = CFrame.new(pos, equation.p)
				--bullet.Trail.Enabled = false
				bullet.Transparency = 1
				bullet.ThudSound:Play()
				if hitParticles and part.Transparency and part.Transparency < 1 then --<<<<<<<<<< CHANGES HERE <<<<<<<<<<<<<<<<<<
					if part.ClassName ~= "Terrain" then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(part.Color)
					elseif material == Enum.Material.Grass
						or material == Enum.Material.LeafyGrass
						or material == Enum.Material.Ground
						or material == Enum.Material.Mud
						or material == Enum.Material.Cobblestone then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(61/255, 51/255, 44/255))
					elseif material == Enum.Material.Asphalt
						or material == Enum.Material.Concrete
						or material == Enum.Material.Pavement
						or material == Enum.Material.Slate then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(100/255, 99/255, 93/255))
					elseif material == Enum.Material.Limestone
						or material == Enum.Material.Sand
						or material == Enum.Material.WoodPlanks then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(172/255, 153/255, 116/255))
					elseif material == Enum.Material.Brick or material == Enum.Material.Sandstone then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(165/255, 114/255, 95/255))
					elseif material == Enum.Material.Rock then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(93/255, 96/255, 103/255))
					elseif material == Enum.Material.Basalt or material == Enum.Material.CrackedLava then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(22/255, 11/255, 10/255))
					elseif material == Enum.Material.Salt or material == Enum.Material.Snow then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(190/255, 180/255, 190/255))
					elseif material == Enum.Material.Glacier or material == Enum.Material.Ice then
						bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color3.new(162/255, 194/255, 217/255))
					end
					bullet.EffectAttachment.DebrisEmitter:Emit(10)
				end
				wait(1)
				for ii, v in pairs(ignoreTable) do
					if v == bullet then
						table.remove(ignoreTable, ii)
					end
				end
				bullet:Destroy()
			else
				bullet.CFrame = equation
			end
			wait(waitBetweenSegments)
		end
	end
	return
end
