Audio isn't playing no matter what I try

I’m working on two scripts for my game which trigger loading and playing audio/music. However, no matter what I try, the audio never seems to actually play, and it never appears in any folders I parent it to.

This is from the local script, after the server modulescript fires off the Name string and the Loop boolean.

local MusicList = {
	["30SEC"] = "rbxassetid://11433668825",
	["LOBBY"] = "rbxassetid://11433664382",
	["SPECTATE"] = "rbxassetid://5355061966",
	["GAME1"] = "rbxassetid://11433670547",
	["GAME2"] = "rbxassetid://11433672214",
	["GAME4"] = "rbxassetid://6882177042",
	["GAME5"] = "rbxassetid://10726457625"
}

local Music = Instance.new("Sound")
Music.Name = Name
Music.Parent = MusicFolder
Music.Looped = Loop
Music.SoundGroup = SoundService.Music.MusicLevel
Music.SoundId = MusicList[Name]

Music:Play()
		
print(Music.Name)

if Music.IsLoaded == true then
	print("music loaded")
end
if Music.IsPlaying == true then
	print("music playing")
end

wait(Music.TimeLength)

if Music.Looped == false then
	Music:Destroy()
end

Here’s the relevant blocks of code. The block beneath the table of audio is inside of a function for playing the audio, which has the arguments ‘Name’ and ‘Loop’.

I added the .IsPlaying, .IsLoaded and the Music.Name checks as a debugging measure, and only the .IsPlaying and the Name printed, which leads me to believe the audio is just never loaded in, for whatever reason.

I’ve checked if the audio is moderated (it isn’t), I’ve parented it to various different places in the workspace, I’ve tried firing different names in the database to no avail. Could someone please help with this? I feel like I’m missing something crucial.

Tl;dr audio no worky

Okay, it doesn’t work. But are there any errors in the console? Maybe Failed to load sound, or something regarding the audio update? Is the audio parented to a BasePart or a non-BasePart?

When do you load the table? The script section below it makes 1 new Sound, but doesn’t loop through the table to load each Sound.

1 Like

Why don’t you create a folder with all the sounds contained in it? Is there a reason you aren’t doing this, and instancing the Sound on the spot when it is needed? Instancing sounds like how you are doing here would cause a small delay in the gameplay due to the nature of Instance.new

You also don’t seem to have too many Sound files to begin with, so having them created preemptively under ReplicatedStorage and referenced on the client will not cause any memory issues or performance drops.

Eg:

local MusicList = {
	["LOBBY"] = ReplicatedStorage.GameAssets.Sounds.Lobby,
}

MusicList[Name]:Play()

You should also add a Preload script in ReplicatedFirst via LocalScript to ensure the sounds are loaded in properly.

Edits: Example changes and added on to my explanation

1 Like

There’s no errors in the output, and Roblox seems to think it’s playing, despite it not being loaded.

I assumed that creating a new Instance whenever I needed the audio (and then destroying it later using a Stop function I have) would be better but now I’ve realised it’s probably a better idea to just have them located in a Folder within ReplicatedStorage.

Everything is working now by the way, I added all of the music to a folder within ReplicatedStorage, and the script uses :GetChildren() to find the music it needs. Thanks for the help!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.