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.

