Sound.IsLoaded becomes false without .Changed firing

(Kinda tempted to post this as a bug report I swear)
So i’m playing some audios on the client, and I preload them by creating the sound objects before they’re actually played (around a few minutes early), and their IsLoaded value becomes true soon after they’re created. However, after a few minutes, when I try to play them, the IsLoaded value shows as false.

Full module code:

local module = {}

local ContentProvider = game:GetService("ContentProvider")
local localPlayer = game:GetService("Players").LocalPlayer
local musicTable = {}
local currentMusic

local musics = require(game:GetService("ReplicatedStorage").GameMusic)

local musicFolder = Instance.new("Folder")
musicFolder.Parent = localPlayer.PlayerGui

function module.loadMusic()
	for i, v in musics.music do
		local tempSound = Instance.new("Sound")
		tempSound.SoundId = "rbxassetid://"..tostring(v.sound)
		tempSound.Volume = 1
		tempSound.PlaybackSpeed = 1
		tempSound.Looped = true
		tempSound.Parent = musicFolder
		tempSound.Name = "Music"..i
		musicTable[v.sound] = tempSound
		tempSound.Changed:Connect(function(val)
			print(v.sound, tempSound:GetFullName())
			print(val)
			print(tempSound[val])
		end)
	end
	task.spawn(function() ContentProvider:PreloadAsync(musicFolder:GetChildren()) end)
	table.freeze(musicTable)
	print(#musicTable.." Length of table")
	print(#musicFolder:GetChildren().." Length of folder")
end 

local function playMusic(id: number, duration: number, recur: number)
	if recur and recur > 5 then return end
	if currentMusic then currentMusic:Stop(); currentMusic = nil end
	if not musicTable[id] then warn("Audio does not exist"); return end
	currentMusic = musicTable[id]
	print(currentMusic)
	print(currentMusic.IsLoaded)
	print(currentMusic:GetFullName())
	print(#musicTable.." Length of table")
	print(#musicFolder:GetChildren().." Length of folder")
	if currentMusic.IsLoaded then
		currentMusic:Play()
	else
		warn("Audio has not loaded:" .. (id or "nil"))
		if not recur then
			task.delay(.5, function() playMusic(id, duration, 1) end)
		else
			task.wait(.5)
			playMusic(id, duration, recur+1)
		end
	end
end

function module.playMusicWithIndex(index: string, duration: number)
	print("Playing music "..index)
	playMusic(musics.music[index].sound, duration)
end

function module.stopAudios()
	if currentMusic then currentMusic:Stop(); currentMusic = nil end
end

return module

(LoadMusic is called when the player joins in a localscript, the playmusic is called later through remoteEvents from the server)



debug prints^

I can garantee that there is never a print for when IsLoaded becomes false even though I have a .Changed event connected

(Ignore how the length of the table is printed as 0, its a dictionary)

(If anyone can confirm that this is a bug that’d be nice too)

Apparently removing the IsLoaded check works, because while IsLoaded is false, the Sound is still loaded

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.