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