Sound Plays in Studio, Not in the Live Game

I reverted to a previous version of my game & the sounds stopped working!

The output:

The hierarchy of what I’m using:

The hover sound: rbxassetid://10066931761
The open sound: rbxassetid://9125397583

Everything works in Studio. The code runs up to the same line and prints before the :Play() method is called

-- This function is called when all of my buttons are clicked
function BUTTON.OnClick(button: TextButton, toCallOnClick)
	if not button.MouseButton1Click then
		return
	end
	
	local connection
	
	button.MouseEnter:Connect(function()
		playHoverSound(button)
		
		local flash: Frame = Instance.new("Frame")
		flash.Size = UDim2.fromScale(0, 0)
		flash.BackgroundColor3 = button.BackgroundColor3
		flash.BackgroundTransparency = 0.5
		flash.BorderSizePixel = 0
		flash.AnchorPoint = Vector2.new(0.5, 0.5)
		flash.Position = UDim2.new(0.5, 0, 0.5, 0)
		flash.Parent = button
		
		flash:TweenSize(UDim2.fromScale(1, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.2)
		Debris:AddItem(flash, 0.2)
	end)
	
	button.SelectionGained:Connect(function()
		playHoverSound(button)
	end)
	
	button.MouseButton1Click:Connect(function()
		playClickSound(button)
		toCallOnClick()
	end)
end

-- This function actually players the sound & is ran when either of the following functions are called (playClickSound or playHoverSound)
function BUTTON.PlaySound(soundName: string, pitch: NumberRange)
	if BUTTON.Cooldowns[soundName] and os.clock() - BUTTON.Cooldowns[soundName] <= 0.08 then
		return
	end
	
	BUTTON.Cooldowns[soundName] = os.clock()
	
	local sound: Sound = script[soundName]:Clone()
	sound.Parent = script["[Playing]"]
	
	if pitch then
		sound.PlaybackSpeed = math.random(pitch.Min, pitch.Max) / 100
	end
	
	sound:Play() -- Prints before this too
	Debris:AddItem(sound, sound.TimeLength) -- Other posts suggest this is the source of the bug
end

-- Just for clarity, these are at the top of the script
local function playClickSound(button)
	if not button:HasTag("MutedButton") then
		BUTTON.PlaySound(button:GetAttribute("ClickSound") or "Select")
	end
end

local function playHoverSound(button)
	BUTTON.PlaySound(button:GetAttribute("HoverSound") or "Hover", NumberRange.new(90, 110))
end

Expected behavior
The sounds played this way only play in Studio, not in the live game. I expect to hear the sounds when I press or hover over a button, but I do not.

Sounds played by other means work all the time.

I can confirm that, for some reason, Debris:AddItem() causes the issue. It should be noted that I spawned about 3,000 meshes for a visual effect & also noticed that they would disappear after hitting some kind of object limit (only when added to the Debris:AddItem queue thing) That’s unrelated to this issue tho.

I can temporarily change that line to sound.Ended & connect a destroy function to it. I haven’t noticed any issues with that approach yet, but I’d much rather be able to use the AddItem approach

Have you checked what value sound.TimeLength has when this occurs in the live game? If the asset takes a bit of time to load, it might have not loaded by the time you’re calling Debris:AddItem() and its value would be 0.

If that’s the issue, listening on sound.Ended would be more resistant to the timing flexibility there. Or you could check sound.IsLoaded and wait on the sound.Loaded event if it’s not.

OMG now I feel dumb. Yes, that makes perfect sense. Some people would say that the sounds were working, but most people said they were not. I guess it never had an issue loading before until now.