local MarketPlace = game:GetService('MarketplaceService')
local contentProvider = game:GetService('ContentProvider')
local sound = script.Parent
local music = {1840373645, 4560587930}
----------- Song Functions
local function checkCopyRight(soundID)
local success, errormsg = pcall(function()
local info = MarketPlace:GetProductInfo(soundID)
local title = info.Name
end)
if success then
return true
elseif errormsg then
print('Music Changing Error: ' .. errormsg)
return false
end
end
local songID -- Global
local function changeSong()
for i=1, #music do
songID = music[i]
if checkCopyRight(songID) then
local audio = 'rbxassetid://' .. songID
contentProvider:Preload(audio)
sound.SoundId = audio
sound:Play()
return
else
changeSong() -- recursive
end
sound.SoundId = songID
end
end
changeSong() -- Set first song
----------- Table functions
local function contains(table, val)
for i=1,#table do
if table[i] == val then
return true
end
end
return false
end
----------- Signals
sound.Ended:Connect(function()
changeSong()
end)
sound.Changed:Connect(function (property)
if property == 'SoundId' then
if contains(music, songID) ~= true then
print('A player has attempted to alter the music ID, though the change should only stay local.')
end
end
end)
I have a script that chooses a random song from a preset table, however errors occur that I don’t know how to solve. First, the errors below appear for every sound ID; afterward one is chosen successfully, but the audio doesn’t play.
Failed to load sound 1840373645: Unable to download sound data
ContentProvider:Preload() failed for rbxassetid://1840373645