For a long time now, while I’ve been creating games, I’ve been running into the problem that all audio files are loaded first and only then played. And if I need to open the UI while the sound is playing, for example, it all looks really awkward and terrible with this delay. Is there a way to fix this? I could make a loading screen with PreloadAsset, but I play audio using a module that creates a sound based on an ID and deletes it when it ends. And even if the player has already played this sound in the UI, after reloading, it will play for the first time again with a delay.
so the sound is completely random and you don’t have it in experience? does player enter ID? where do you get it?..
If I need to play a sound in a game, I upload the audio to Roblox and insert the ID into the script. The sound is played from the module that creates the audio, inserts the ID, and deletes it when finished. However, all the sounds don’t play immediately, and it takes time to load. I’m looking for this solution.
-- code
Library.Audio:PlaySound("rbxassetid://MY_ID", false, script, 1, game["SoundService"].SFX)
-- code
So, I just load all the rbxassetids, and if later in the audio module it finds them in a special folder, then it plays, so they are already loaded
for _, Sound in pairs(ReplicatedStorage.Temp.Sounds:GetChildren()) do
if Sound.SoundId == Id then
Sound:Play()
return Sound
end
end
function Functions:PreloadSound(Sounds)
local ToPreload = {}
for _, Sound in ipairs(Sounds) do
local NewSound = Instance.new("Sound", ReplicatedStorage.Temp.Sounds)
NewSound.SoundId = Sound
table.insert(ToPreload, NewSound)
end
ContentProvider:PreloadAsync(ToPreload)
end