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


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)
