Plugin music script, how to loop and how to stop music in studio, math.random always picking only two songs

I want to be able to randomly pick music every time the plugin is started up, and when the plugin closes it stops the music, but every time I start up the plugin it only picks two songs out of 6, sometimes it even plays the same song multiple times, and when I close the plugin the song still keeps playing even though it prints it destroyed the song, any help appreciated!
(Note, audio id is cut out due to development reasons, they dont impact the code)

local PLAYLIST = {"rbxassetid://0000000000","rbxassetid://0000000000","rbxassetid://0000000000","rbxassetid://0000000000","rbxassetid://0000000000","rbxassetid://0000000000"}

local SoundService = game:GetService("SoundService")
local getSound
local function playLocalSound(soundId)
	-- Create a sound
	local sound ="Sound")
	sound.SoundId = soundId
	sound.Volume = 10
	getSound = sound
	-- Play the sound locally
	if getSound then
		game.Debris:AddItem(getSound, 0)

local function onNewScriptButtonClicked()
	script.Parent.Parent = game.StarterGui
	script.Parent.Enabled = true
	local SONG = PLAYLIST[math.random(1, #PLAYLIST)]

local function EXIT()
	script.Parent.Enabled = false
	if getSound then
		if pcall(function() getSound:Destroy() end) then
			print("Sound has been completely destroyed.")


math.random doesn’t work very well unless you do some annoying workarounds. If you use the new-ish Random class instead, you should see better random distributions in your game. You use it like so:

local rng =
local randomInt = rng:NextInteger(low, high)
local randomFloat = rng:NextNumber(low, high)

function pickRandom(list)
    return list[rng:NextNumber(1, #list)]

function pickAndRemoveRandom(list)
    local index = rng:NextNumber(1, #list)
    local value = list[index]
    table.remove(list, index)
    return value

local randomItem = pickRandom(list)

This wont help with songs being played repeatedly, because randomly picking a song means you can pick the one that was just played. The way to do it is to shuffle the list, then go through it in the new (random) order. There’s lots of shuffling algo implementations online, here’s one that works: