--Creates a random droplet on screen

local function CreateDroplet()
	--Setup
	local DecidedSize = Random_:NextNumber(0.01,0.07)
	local stretch = 1 + math.random(15) / 10

	local RunAmount = math.random(4)
	local Tweens = table.create(RunAmount * 2 + 2)
	local TweensLength = 0

	local SizeOffset = math.random((DecidedSize / 3) * -10, (DecidedSize / 3) * 10) / 10
	local Scale = DecidedSize + SizeOffset
	local MeshScale = Vector3.new(Scale, Scale, Scale)

	--Main droplet object
	local DropletMain = Instance.new("Part")
	DropletMain.Material = Enum.Material.Glass
	DropletMain.CFrame = EMPTY_CFRAME
	DropletMain.CanCollide = false
	DropletMain.Transparency = 0.5
	DropletMain.Name = "Droplet_Main"
	DropletMain.Color = Color3.fromRGB(255, 255, 255)
	DropletMain.Size = DROPLET_SIZE

	local Mesh = Instance.new("SpecialMesh")
	Mesh.MeshType = Enum.MeshType.Sphere
	Mesh.Scale = MeshScale
	Mesh.Parent = DropletMain

	--Create droplet extrusions
	for i = 1, RunAmount do
		local eSizeOffset = math.random(
			(DecidedSize / 3) * -100,
			(DecidedSize / 3) * 100
		) / 100

		local ExtrusionCFrame = CFrame.new(Vector3.new(
			math.random(-(DecidedSize * 40), DecidedSize * 40) / 100,
			math.random(-(DecidedSize * 40), DecidedSize * 40) / 100,
			0
		))

		local ExtrusionScale = DecidedSize / 1.5 + eSizeOffset
		local ExtrusionMeshScale = Vector3.new(ExtrusionScale, ExtrusionScale, ExtrusionScale)

		local Extrusion = Instance.new("Part")
		Extrusion.Material = Enum.Material.Glass
		Extrusion.CFrame = ExtrusionCFrame
		Extrusion.CanCollide = false
		Extrusion.Transparency = 0.5
		Extrusion.Name = "Extrusion_" .. i
		Extrusion.Color = Color3.fromRGB(255, 255, 255)
		Extrusion.Size = DROPLET_SIZE

		local ExtrusionMesh = Instance.new("SpecialMesh")
		ExtrusionMesh.MeshType = Enum.MeshType.Sphere
		ExtrusionMesh.Scale = ExtrusionMeshScale
		ExtrusionMesh.Parent = Extrusion
		Extrusion.Parent = DropletMain

		local weld = Instance.new("Weld")
		weld.C0 = ExtrusionCFrame:Inverse() * EMPTY_CFRAME
		weld.Part0 = Extrusion
		weld.Part1 = DropletMain
		weld.Parent = Extrusion

		IgnoreLength = IgnoreLength + 1
		TweensLength = TweensLength + 1
		ignoreList[IgnoreLength] = Extrusion
		Tweens[TweensLength] = TweenService:Create(Extrusion, fadeInfo, fadeGoal)

		TweensLength = TweensLength + 1
		Tweens[TweensLength] = TweenService:Create(ExtrusionMesh, strechInfo, {
			Scale = Vector3.new(ExtrusionScale, ExtrusionScale * stretch, ExtrusionScale);
			Offset = Vector3.new(0, -(ExtrusionScale * stretch) / 2.05, 0);
		})
	end

	IgnoreLength = IgnoreLength + 1
	TweensLength = TweensLength + 1
	ignoreList[IgnoreLength] = DropletMain
	Tweens[TweensLength] = TweenService:Create(DropletMain, fadeInfo, fadeGoal)

	TweensLength = TweensLength + 1
	Tweens[TweensLength] = TweenService:Create(Mesh, strechInfo, {
		Scale = Vector3.new(Scale, Scale * stretch, Scale);
		Offset = Vector3.new(0, -(Scale * stretch) / 2.05, 0);
	})

	local NewCFrame = ScreenBlockCFrame:ToWorldSpace(CFrame.new(
		math.random(-100, 100) / 100,
		math.random(-100, 100) / 100,
		-1
	))

	DropletMain.CFrame = NewCFrame
	local weld = Instance.new("Weld")
	weld.C0 = NewCFrame:Inverse() * ScreenBlockCFrame
	weld.Part0 = DropletMain
	weld.Part1 = ScreenBlock
	weld.Parent = DropletMain

	for _, t in ipairs(Tweens) do
		t:Play()
	end

	local DestroyRoutine = coroutine.create(DestroyDroplet)
	coroutine.resume(DestroyRoutine, DropletMain)
	DropletMain.Parent = ScreenBlock
end

local function OnGraphicsChanged()
	CanShow = GameSettings.SavedQualityLevel.Value >= 8
end

GameSettings:GetPropertyChangedSignal("SavedQualityLevel"):Connect(OnGraphicsChanged)
