Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Sound failed to load in, file not found?

I've been having an issue where my background music in my game fails with the error Sound failed to load in, file not found

How does one fix this?

The script I'm using for it:

sound = Instance.new("Sound", game.SoundService)
sound.Name = "Background"

ids = {344852871 ,177081124 , 230210363, 963703151, 222354401, 444071223, 530579604, 166465461, 156469449}


local Audio = "rbxassetid://" .. ids[math.random(1,#ids)] 
local ContentProvider = game:GetService("ContentProvider")
		print(Audio)
		ContentProvider:Preload(Audio)
sound.SoundId = Audio
sound:Play()


sound.Ended:connect(function()
local Audio = "rbxassetid://" .. ids[math.random(1,#ids)] 
local ContentProvider = game:GetService("ContentProvider")
		print(Audio)
		ContentProvider:Preload(Audio)
sound.SoundId = Audio
sound:Play()
end)

3 comments

0

This always happens, there is no fix for it, even if you use a pcall.

0

^that has an answer that explains

2 answers

Try using a different URL scheme when specifying the SoundId, that might work better. This example was ripped from this page on the wiki. Also you can improve your script by not repeating yourself. I'll do that here so the script I post is shorter. I moved your anonymous function into a named one.

sound = Instance.new("Sound", game.SoundService)
sound.Name = "Background"

ids = {344852871 ,177081124 , 230210363, 963703151, 222354401, 444071223, 530579604, 166465461, 156469449}

function playRandomAudio()
    local Audio = "http://www.roblox.com/asset/?id=" .. ids[math.random(1,#ids)] 
    local ContentProvider = game:GetService("ContentProvider")
    print(Audio)
    ContentProvider:Preload(Audio)
    sound.SoundId = Audio
    sound:Play()
end

sound.Ended:connect(playRandomAudio)

playRandomAudio()

1 comment

0

It runs for a bit but I still get the error. You'd think roblox would've made a fix by now.

Like what kools said, you have to use a URL or file path.

Simply providing an ID does not work in a script like it does in studio - you have to give the value a specific path. This is done by giving a link to a specific ROBLOX asset online;

rbxassetid://0000 > User-created asset on the website

http://www.roblox.com/asset/?id=0000 > Asset on the website

The wiki article on this is http://www.wiki.roblox.com/index.php?title=Content.


Hope I helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.