--------------------[ TEXTURE CREATION FUNCTIONS ]------------------------------------

function CreateBullet(Direction)
	local Origin = Gun.Main.CFrame.p
	local BulletMass = S.BulletSize.X * S.BulletSize.Y * S.BulletSize.Z
	local BulletCF = CF(Origin, Origin + Direction)
	local Bullet = Instance.new("Part")
	Bullet.BrickColor = S.BulletColor
	Bullet.Name = "Bullet"
	Bullet.CanCollide = false
	Bullet.FormFactor = "Custom"
	Bullet.Size = S.BulletSize
	Bullet.BottomSurface = "Smooth"
	Bullet.TopSurface = "Smooth"
	local Mesh = Instance.new("BlockMesh")
	Mesh.Scale = S.BulletMeshSize
	Mesh.Parent = Bullet
	local BF = Instance.new("BodyForce")
	BF.force = VEC3(0, BulletMass * (196.2 - S.BulletDropPerSecond), 0)
	BF.Parent = Bullet
	Bullet.Parent = Gun_Ignore
	Bullet.CFrame = BulletCF + Direction * 3
	Bullet.Velocity = Direction * S.BulletVelocity
	return Bullet
end

function CreateBulletHole(HitPos, HitObj)
	local SurfaceCF = GetHitSurfaceCFrame(HitPos, HitObj)
	local SurfaceDir = CF(HitObj.CFrame.p, SurfaceCF.p)
	local SurfaceDist = SurfaceDir.lookVector * (HitObj.CFrame.p - SurfaceCF.p).magnitude / 2
	local SurfaceOffset = HitPos - SurfaceCF.p + SurfaceDist
	local SurfaceCFrame = SurfaceDir + SurfaceDist + SurfaceOffset
	local HitMark = Instance.new("Part")
	HitMark.BrickColor = BrickColor.new("Black")
	HitMark.Transparency = 1
	HitMark.Anchored = true
	HitMark.CanCollide = false
	HitMark.FormFactor = "Custom"
	HitMark.Size = VEC3(1, 1, 0.2)
	HitMark.TopSurface = 0
	HitMark.BottomSurface = 0
	local Mesh = Instance.new("BlockMesh")
	Mesh.Offset = VEC3(0, 0, -0.05)
	Mesh.Scale = VEC3(S.BulletHoleSize, S.BulletHoleSize, 0)
	Mesh.Parent = HitMark
	local Decal = Instance.new("Decal")
	Decal.Face = Enum.NormalId.Front
	Decal.Texture = S.BulletHoleTexture
	Decal.Parent = HitMark
	HitMark.Parent = Gun_Ignore
	HitMark.CFrame = SurfaceCFrame
	if (not HitObj.Anchored) then
		local Weld = Instance.new("Weld", HitMark)
		Weld.Part0 = HitObj
		Weld.Part1 = HitMark
		Weld.C0 = HitObj.CFrame:toObjectSpace(SurfaceCFrame)
		HitMark.Anchored = false
	end
	delay(S.BulletHoleVisibleTime, function()
		if S.BulletHoleDisappearTime > 0 then
			local X = 0
			while true do
				if X == 90 then break end
				if (not Selected) then break end
				local NewX = X + (1.5 / S.BulletHoleDisappearTime)
				X = (NewX > 90 and 90 or NewX)
				local Alpha = X / 90
				Decal.Transparency = NumLerp(0, 1, Alpha)
				RS:wait()
			end
			HitMark:Destroy()
		else
			HitMark:Destroy()
		end
	end)
end

function CreateShockwave(Center, Radius)
	local Shockwave = Instance.new("Part")
	Shockwave.BrickColor = S.ShockwaveColor
	Shockwave.Material = Enum.Material.SmoothPlastic
	Shockwave.Name = "Shockwave"
	Shockwave.Anchored = true
	Shockwave.CanCollide = false
	Shockwave.FormFactor = Enum.FormFactor.Symmetric
	Shockwave.Size = VEC3(1, 1, 1)
	Shockwave.BottomSurface = Enum.SurfaceType.Smooth
	Shockwave.TopSurface = Enum.SurfaceType.Smooth
	local Mesh = Instance.new("SpecialMesh")
	Mesh.MeshType = Enum.MeshType.Sphere
	Mesh.Scale = VEC3()
	Mesh.Parent = Shockwave
	Shockwave.Parent = Gun_Ignore
	Shockwave.CFrame = CF(Center)
	spawn(function()
		for i = 0, 1, (1 / (60 * S.ShockwaveDuration)) do
			local Scale = 2 * Radius * i
			Mesh.Scale = VEC3(Scale, Scale, Scale)
			Shockwave.Transparency = i
			RS:wait()
		end
		Shockwave:Destroy()
	end)
end