I’m not 100% that this is the case, but I’m pretty confident - this has caused some odd behavior in my game and the only reason I could think of that would make it occur is this.
I’m using a marginally modified version of the AudioPlayer module from the Roblox Developer website and I ran into this problem. My reasoning for the fact that the line
if not audio.IsLoaded then audio.Loaded:wait()
can wait forever is that in some servers I observe the buggy behavior 100% of the time, while in others I observe the buggy behavior 0% of the time. Am I perhaps loading in my audio improperly? I’m using
in a serverscript, with each Audio snippet played during a particular action. Incidentally, the action that is broken will be different per bugged server. The only difference between my module and the one from the Roblox Developer website is that I’m loading the audio into a folder in ReplicatedStorage as opposed to workspace.
I’m wondering if the mentioned line can wait forever - I’ve been hunting this bug for ages and I can’t think of anything else at this point.
local AudioPlayer = {}
local ContentProvider = game:GetService("ContentProvider")
local audioAssets = game.ReplicatedStorage.Assets.Audio
-- Function to preload audio assets
AudioPlayer.preloadAudio = function(assetArray)
local toLoad = {}
for name, audioID in pairs(assetArray) do
local audioInstance = Instance.new("Sound")
audioInstance.SoundId = "rbxassetid://" .. audioID
audioInstance.Name = name
audioInstance.Parent = audioAssets
table.insert(toLoad, audioInstance)
end
local success, assets = pcall(function()
ContentProvider:PreloadAsync(toLoad)
end)
end
-- Function to play an audio asset
AudioPlayer.playAudio = function(assetName, properties)
local audio = audioAssets:FindFirstChild(assetName)
assert(audio, "Could not find audio asset: " .. assetName)
if not audio.IsLoaded then audio.Loaded:wait() end
local newAudio = audio:Clone()
for property, value in pairs(properties) do
newAudio[property] = value
end
newAudio:Play()
game.Debris:AddItem(newAudio, newAudio.TimeLength + 0.5)
end
return AudioPlayer