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)
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()
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!