Unable to cast to Array

I have been trying to use ContentProvider to preload my music, but whenever I try to run my game, the code will always put on a error in the console saying Unable to Cast to array. Is there any mistakes that I had potentially put inside the code?

PreloadAsync takes an array but you’re passing through an object. Should be written like this:

		local assets = {}
		for i, v in game.ReplicatedStorage:WaitForChild("Music"):GetChildren() do
			table.insert(asset, v)
		end
		
		ContentProvider:PreloadAsync(asset)

cheers

dajfaslkdjf;asldkfj;asldkfj;lksaj 30

1 Like

game.ReplicatedStorage:WaitForChild("Music"):GetChildren() already returns an array, making a new table is useless. You can do this:

ContentProvider:PreloadAsync(game.ReplicatedStorage:WaitForChild("Music"):GetChildren())
1 Like

Good catch

2 Likes

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