Preloading sounds doesn't work?

I’m trying to preload module sounds when the game first starts. code for the sound module:


and so on.

I got preloading weapons (they have sounds inside of them too) to work just fine, but the game just doesn’t want to load any asset IDs from here.

-- STUFF LOADING
local replicatedStorage = game:GetService("ReplicatedStorage")
local contentProvider = game:GetService("ContentProvider")

-- bla bla

local function notePreloadAsset(id)
	if type(id) ~= "string" then return end
	print("-------------")
	print("Loading "..id)
	-- output always provides a valid asset ID, never a table memory address
	contentProvider:PreloadAsync({ tostring(id) })
end

-- bla bla

print("Loading sounds")

function scan(item)

	if type(item) == "table" then
	--	notePreloadAsset(item) 
		for i,v in pairs(item) do  
			scan(v)
		end
	elseif type(item) == "string" then 
		notePreloadAsset(item)
	end 

end 

for _,tbl in pairs(resourceModule) do
	for i,v in pairs(tbl) do
		scan(v)
	end 
end 

It loads the first part notePreload just fine, but the moment sounds start preloading, every single one of them fails

  rbxassetid://4546464750
  Loaded
  rbxassetid://4546542797
  Loaded
  rbxassetid://3446917718
  Loaded
  rbxassetid://4546461227
  Loaded
  rbxassetid://4565061617
  Loading sounds
  -------------
  Loading rbxassetid://3689682801
11:43:09.111 - ContentProvider:PreloadAsync() failed for rbxassetid://3689682801
  -------------
  Loading rbxassetid://3689683132
11:43:09.145 - ContentProvider:PreloadAsync() failed for rbxassetid://3689683132
  -------------
  Loading rbxassetid://4776517267
11:43:09.178 - ContentProvider:PreloadAsync() failed for rbxassetid://4776517267
  -------------
  Loading rbxassetid://4776516378
11:43:09.212 - ContentProvider:PreloadAsync() failed for rbxassetid://4776516378
  -------------
  Loading rbxassetid://4776516615
11:43:09.247 - ContentProvider:PreloadAsync() failed for rbxassetid://4776516615
  -------------
  Loading rbxassetid://4776516160
11:43:09.279 - ContentProvider:PreloadAsync() failed for rbxassetid://4776516160
  -------------
  Loading rbxassetid://4776516905
11:43:09.312 - ContentProvider:PreloadAsync() failed for rbxassetid://4776516905
  -------------

How do I get the asset IDs to load in?

1 Like

I’m not quite sure if this will help, but it says on the wiki they use Instances in the array, not strings or integers.

1 Like

Time to spam new sound instances, i guess.

1 Like

Wow, it worked.

I would feel bad for your code if you forget to delete it after it’s finished.

Still questioning why your other one doesn’t work. Compare it to the PreloadAsync example in the wiki maybe?

1 Like

If you pass in id strings (the old way), those ids will be assumed as images, other types will failed to request. This will cause some error messages printed out. Edit: Sorry for the trouble I caused today. I’ve turned this off. Now you can take your time to make an update.

It assumes they’re images now.

As wacky as that solution is, it doesn’t seem to do much performance wise anyway, so you should be fine.

3 Likes

If it’s stupid and it works, it’s not stupid!

4 Likes