Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sound failed to load in, file not found?

Asked by 7 years ago
Edited 7 years ago

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)
0
This always happens, there is no fix for it, even if you use a pcall. hiimgoodpack 2009 — 7y
0
^that has an answer that explains abnotaddable 920 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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()
0
It runs for a bit but I still get the error. You'd think roblox would've made a fix by now. EddieLJones 15 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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!

Answer this question