local a=script:WaitForChild("\099\114\101\097\116\101\066\117\108\108\101\116\073\109\112\097\099\116")a.OnServerEvent:connect(function(a,k,V,l,n,C,T,L)local i=CF(V,V+l)if L.bulletHoles and not C then local a=Instance.new("\080\097\114\116")a.Transparency=1 a.Anchored=true a.CanCollide=false a.FormFactor="\067\117\115\116\111\109"a.Size=V3(1,1,.2)a.TopSurface=0 a.BottomSurface=0 local V=Instance.new("\066\108\111\099\107\077\101\115\104")V.Offset=V3(0,0,-0.05)V.Scale=V3(L.holeSettings.Size,L.holeSettings.Size,0)V.Parent=a local l=Instance.new("\068\101\099\097\108")l.Face=Enum.NormalId.Front l.Texture=L.holeSettings.Texture l.Parent=a a.Parent=T a.CFrame=i if not k.Anchored then local V=Instance.new("\087\101\108\100",a)V.Part0=k V.Part1=a V.C0=k.CFrame:toObjectSpace(i)a.Anchored=false end delay(L.holeSettings.visibleTime,function()if L.holeSettings.disappearTime>0 then local k=tick()while true do local a=math.min((tick()-k)/L.holeSettings.disappearTime,1)l.Transparency=numLerp(0,1,a)if a==1 then break end wait()end a:Destroy()else a:Destroy()end end)end if L.bulletSparks and(not C and inList(k.Material,L.sparkSettings.Materials))then local a=Instance.new("\080\097\114\116")a.Transparency=1 a.Anchored=true a.CanCollide=false a.FormFactor="\067\117\115\116\111\109"a.Size=V3(1,1,1)a.TopSurface=0 a.BottomSurface=0 local V=Instance.new("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")V.Color=ColorSequence.new(L.sparkSettings.Color)V.LightEmission=1 V.Size=NumberSequence.new(L.sparkSettings.Size)V.Texture=L.sparkSettings.Texture V.Transparency=NumberSequence.new({NumberSequenceKeypoint.new(0,.25,.25);NumberSequenceKeypoint.new(1,1)})V.Acceleration=V3(0,-196.2,0)V.EmissionDirection=Enum.NormalId.Front V.Lifetime=NumberRange.new(L.sparkSettings.Lifetime-.05,L.sparkSettings.Lifetime+.05)V.Rate=L.sparkSettings.Rate V.RotSpeed=NumberRange.new(360)V.Speed=NumberRange.new(L.sparkSettings.Speed-5,L.sparkSettings.Speed+5)V.VelocitySpread=L.sparkSettings.Spread V.Parent=a a.Parent=T a.CFrame=i if not k.Anchored then local V=Instance.new("\087\101\108\100",a)V.Part0=k V.Part1=a V.C0=k.CFrame:toObjectSpace(i)a.Anchored=false end delay(.1,function()V.Enabled=false wait(L.sparkSettings.Lifetime+.05)a:Destroy()end)end if L.bulletSmoke and not C then local a=Instance.new("\080\097\114\116")a.Transparency=1 a.Anchored=true a.CanCollide=false a.FormFactor="\067\117\115\116\111\109"a.Size=V3(1,1,1)a.TopSurface=0 a.BottomSurface=0 local V=Instance.new("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")V.Color=ColorSequence.new(L.smokeSettings.objColor and k.Color or L.smokeSettings.Color)V.LightEmission=0 V.Size=NumberSequence.new({NumberSequenceKeypoint.new(0,L.smokeSettings.Size.Start),NumberSequenceKeypoint.new(1,L.smokeSettings.Size.End)})V.Texture=L.smokeSettings.Texture V.Transparency=NumberSequence.new({NumberSequenceKeypoint.new(0,L.smokeSettings.startTransparency);NumberSequenceKeypoint.new(.5,.75*L.smokeSettings.startTransparency+.25),NumberSequenceKeypoint.new(1,1)})V.Acceleration=V3(0,-196.2,0)V.EmissionDirection=Enum.NormalId.Front V.Lifetime=NumberRange.new(L.smokeSettings.Lifetime-.05,L.smokeSettings.Lifetime+.05)V.Rate=L.smokeSettings.Rate V.Rotation=NumberRange.new(0,360)V.RotSpeed=NumberRange.new(10)V.Speed=NumberRange.new(L.smokeSettings.Speed-5,L.smokeSettings.Speed+5)V.VelocitySpread=L.smokeSettings.Spread V.Parent=a a.Parent=T a.CFrame=i if not k.Anchored then local V=Instance.new("\087\101\108\100",a)V.Part0=k V.Part1=a V.C0=k.CFrame:toObjectSpace(i)a.Anchored=false end delay(.1,function()V.Enabled=false wait(L.smokeSettings.Lifetime+.05)a:Destroy()end)end end)
----------------------------------------------------------------------
--------------------[ BULLET IMPACT HANDLING ]------------------------
----------------------------------------------------------------------

local createBulletImpact = script:WaitForChild("createBulletImpact")
createBulletImpact.OnServerEvent:connect(function(_, H, P, N, D, humanoidFound, gunIgnore, S)
	local surfaceCF = CF(P, P + N)
	----------------------------------------------------------------------------------
	--Creating the bullet hole--------------------------------------------------------
	----------------------------------------------------------------------------------
	if S.bulletHoles and not humanoidFound then
		local Hole = Instance.new("Part")
		Hole.Transparency = 1
		Hole.Anchored = true
		Hole.CanCollide = false
		Hole.FormFactor = "Custom"
		Hole.Size = V3(1, 1, 0.2)
		Hole.TopSurface = 0
		Hole.BottomSurface = 0
		local Mesh = Instance.new("BlockMesh")
		Mesh.Offset = V3(0, 0, -0.05)
		Mesh.Scale = V3(S.holeSettings.Size, S.holeSettings.Size, 0)
		Mesh.Parent = Hole
		local Decal = Instance.new("Decal")
		Decal.Face = Enum.NormalId.Front
		Decal.Texture = S.holeSettings.Texture
		Decal.Parent = Hole
		Hole.Parent = gunIgnore
		Hole.CFrame = surfaceCF
		if not H.Anchored then
			local Weld = Instance.new("Weld", Hole)
			Weld.Part0 = H
			Weld.Part1 = Hole
			Weld.C0 = H.CFrame:toObjectSpace(surfaceCF)
			Hole.Anchored = false
		end
		delay(S.holeSettings.visibleTime, function()
			if S.holeSettings.disappearTime > 0 then
				local t0 = tick()
				while true do
					local Alpha = math.min((tick() - t0) / S.holeSettings.disappearTime, 1)
					Decal.Transparency = numLerp(0, 1, Alpha)
					if Alpha == 1 then
						break
					end
					wait()
				end
				Hole:Destroy()
			else
				Hole:Destroy()
			end
		end)
	end
	----------------------------------------------------------------------------------
	--Creating the spark effect-------------------------------------------------------
	----------------------------------------------------------------------------------
	if S.bulletSparks and not humanoidFound and inList(H.Material, S.sparkSettings.Materials) then
		local Sparks = Instance.new("Part")
		Sparks.Transparency = 1
		Sparks.Anchored = true
		Sparks.CanCollide = false
		Sparks.FormFactor = "Custom"
		Sparks.Size = V3(1, 1, 1)
		Sparks.TopSurface = 0
		Sparks.BottomSurface = 0

		local Particles = Instance.new("ParticleEmitter")
		Particles.Color = ColorSequence.new(S.sparkSettings.Color)
		Particles.LightEmission = 1
		Particles.Size = NumberSequence.new(S.sparkSettings.Size)
		Particles.Texture = S.sparkSettings.Texture
		Particles.Transparency = NumberSequence.new({
			NumberSequenceKeypoint.new(0, 0.25, 0.25),
			NumberSequenceKeypoint.new(1, 1),
		})
		Particles.Acceleration = V3(0, -196.2, 0)
		Particles.EmissionDirection = Enum.NormalId.Front
		Particles.Lifetime = NumberRange.new(S.sparkSettings.Lifetime - 0.05, S.sparkSettings.Lifetime + 0.05)
		Particles.Rate = S.sparkSettings.Rate
		Particles.RotSpeed = NumberRange.new(360)
		Particles.Speed = NumberRange.new(S.sparkSettings.Speed - 5, S.sparkSettings.Speed + 5)
		Particles.VelocitySpread = S.sparkSettings.Spread
		Particles.Parent = Sparks

		Sparks.Parent = gunIgnore
		Sparks.CFrame = surfaceCF
		if not H.Anchored then
			local Weld = Instance.new("Weld", Sparks)
			Weld.Part0 = H
			Weld.Part1 = Sparks
			Weld.C0 = H.CFrame:toObjectSpace(surfaceCF)
			Sparks.Anchored = false
		end
		delay(0.1, function()
			Particles.Enabled = false
			wait(S.sparkSettings.Lifetime + 0.05)
			Sparks:Destroy()
		end)
	end
	----------------------------------------------------------------------------------
	--Creating the smoke effect-------------------------------------------------------
	----------------------------------------------------------------------------------
	if S.bulletSmoke and not humanoidFound then
		local Smoke = Instance.new("Part")
		Smoke.Transparency = 1
		Smoke.Anchored = true
		Smoke.CanCollide = false
		Smoke.FormFactor = "Custom"
		Smoke.Size = V3(1, 1, 1)
		Smoke.TopSurface = 0
		Smoke.BottomSurface = 0

		local Particles = Instance.new("ParticleEmitter")
		Particles.Color = ColorSequence.new(S.smokeSettings.objColor and H.Color or S.smokeSettings.Color)
		Particles.LightEmission = 0
		Particles.Size = NumberSequence.new({
			NumberSequenceKeypoint.new(0, S.smokeSettings.Size.Start),
			NumberSequenceKeypoint.new(1, S.smokeSettings.Size.End),
		})
		Particles.Texture = S.smokeSettings.Texture
		Particles.Transparency = NumberSequence.new({
			NumberSequenceKeypoint.new(0, S.smokeSettings.startTransparency),
			NumberSequenceKeypoint.new(0.5, 0.75 * S.smokeSettings.startTransparency + 0.25),
			NumberSequenceKeypoint.new(1, 1),
		})
		Particles.Acceleration = V3(0, -196.2, 0)
		Particles.EmissionDirection = Enum.NormalId.Front
		Particles.Lifetime = NumberRange.new(S.smokeSettings.Lifetime - 0.05, S.smokeSettings.Lifetime + 0.05)
		Particles.Rate = S.smokeSettings.Rate
		Particles.Rotation = NumberRange.new(0, 360)
		Particles.RotSpeed = NumberRange.new(10)
		Particles.Speed = NumberRange.new(S.smokeSettings.Speed - 5, S.smokeSettings.Speed + 5)
		Particles.VelocitySpread = S.smokeSettings.Spread
		Particles.Parent = Smoke

		Smoke.Parent = gunIgnore
		Smoke.CFrame = surfaceCF
		if not H.Anchored then
			local Weld = Instance.new("Weld", Smoke)
			Weld.Part0 = H
			Weld.Part1 = Smoke
			Weld.C0 = H.CFrame:toObjectSpace(surfaceCF)
			Smoke.Anchored = false
		end
		delay(0.1, function()
			Particles.Enabled = false
			wait(S.smokeSettings.Lifetime + 0.05)
			Smoke:Destroy()
		end)
	end
end)
