Preload plugin sounds as Sound instances

preloadAssets handed every string in Assets to ContentProvider:PreloadAsync,
which fetches a bare string as an image. The Notification sound
(rbxassetid://203785492) therefore failed with "Asset type does not match
requested type" in Studio's output each time the plugin loaded. Everything
under Assets.Sounds is now preloaded as a Sound instance, which loads its
SoundId as audio; all other assets are preloaded as before.

Fixes #1342

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYrG5tMSJQyEynTw6Uwhcx
This commit is contained in:
VCRhythm 2026-10-16 18:31:00 -04:00
parent 7e60406373
commit a7eac93d5d

View file

@ -21,12 +21,38 @@ function gatherAssetUrlsRecursive(currentTable, currentUrls)
end
local function preloadAssets()
local contentUrls = gatherAssetUrlsRecursive(Assets)
local contentUrls = {}
local soundUrls = {}
for key, value in Assets do
if key == "Sounds" then
gatherAssetUrlsRecursive(value, soundUrls)
elseif typeof(value) == "string" then
table.insert(contentUrls, value)
elseif typeof(value) == "table" then
gatherAssetUrlsRecursive(value, contentUrls)
end
end
Log.trace("Preloading assets: {:?}", contentUrls)
Log.trace("Preloading sounds: {:?}", soundUrls)
-- PreloadAsync fetches a bare string as an image, so sounds go in as Sound
-- instances, which load their SoundId as audio.
local preloadList = table.clone(contentUrls)
local sounds = {}
for _, soundId in soundUrls do
local sound = Instance.new("Sound")
sound.SoundId = soundId
table.insert(sounds, sound)
table.insert(preloadList, sound)
end
coroutine.wrap(function()
ContentProvider:PreloadAsync(contentUrls)
ContentProvider:PreloadAsync(preloadList)
for _, sound in sounds do
sound:Destroy()
end
end)()
end