Trouble Preloading Sounds

I want to preload a table of sound IDs, but it keeps erroring with the below:

-- CODE
for _, v in pairs(stations[stationName]) do
    if v then
         sound.SoundId = "rbxassetid://" .. tostring(v)
         print(sound.SoundId)
         ContentProvider:PreloadAsync({sound})
    end
end
OUTPUT:
  rbxassetid://1843404009
  rbxassetid://1836743584
  rbxassetid://1847588120
21:15:30.808 - Failed to load sound rbxassetid://nil: Unable to download sound data
1 Like

Well it appears somewhere in a table you might have a nil. Scan through to make sure there’s nothing nil (on the station being called), alternatively a wider view of your script might be able to help us in helping you.

Edit: I tried the code you provided creating my own table and encountered no issues with it trying to load a nil asset.

Everything that was being loaded was printed out here, sorry about the confusion:

I wasn’t able to replicate your issue with your current code provided, are you able to show more of your script as it would be easier to identify an issue.

try changing your if statement in the for loop to this:

if tonumber(v) then

so the new code should be:

for _, v in pairs(stations[stationName]) do
    if tonumber(v) then
         sound.SoundId = "rbxassetid://" .. tostring(v)
         print(sound.SoundId)
         ContentProvider:PreloadAsync({sound})
    end
end
1 Like