If not audio.IsLoaded then audio.Loaded:wait() end waits forever

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

audioPlayer.preloadAudio({
	["Audio1"] = theId,
	["Audio2"] = theId,
	["Audio3"] = theId
})

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.

1 Like

Show the whole script so I can see what is the error
(Just a thing but why do you repeat theId?)

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

(I dont think this is how it is in your script but…) Uppercase If

It should be if

Mistake in copying the code, it’s lowercase if in the script.

Ok so there is a audio player module and there is a server script right?

Be sure the server script aint on the replicated storage

I dont have any idea what would be the solution for this though

Change if not audio.IsLoaded then audio.Loaded:wait()
to if audio.IsLoaded == false then audio.Loaded:Wait()