Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How shall I fix this Music Player script?

Hey, my nephew has made this Music Player script, yet it doesn't work. It's supposed to play one song, then when that finishes, it plays the next, and just keeps going, then loops back to the first one etc.

The errors in the console are things like this; ContentProvider:PreloadAsync() failed for rbxassetid://413625451

But the ID is different each time, and it prints them really fast.

I have no idea how to fix this, here is my code;

local cp = game:GetService('ContentProvider')

local assets = {
'rbxassetid://413625451',
'rbxassetid://142281425',
'rbxassetid://986301757',
'rbxassetid://327081386',
'rbxassetid://243372213',
'rbxassetid://887339742',
'rbxassetid://877806338',
'rbxassetid://697236118',
'rbxassetid://229990159',
'rbxassetid://333302122',
'rbxassetid://765968440',
'rbxassetid://430028323',
'rbxassetid://972103544',
'rbxassetid://931034724',
'rbxassetid://869684560',
}
cp:PreloadAsync(assets)

local music = Instance.new("Sound")
music.Archivable = true
music.Parent = script.Parent
music.Looped = true
music.Pitch = 1
music.Volume = 1
music.Name = "Music"

for i = 1, #assets do
	music.SoundId = i
	music:Play()
end

2 comments

0

You can't fix this. It is like asking "How can I prevent my internet from having glitches?"

0

It's an error with the ROBLOX core scripts.

1 answer

✓ Accepted answer

EDIT: I would recommend getting rid of the strings in your table and only putting the id numbers so you can use this (to be honest I don't know if you have to replace the strings with the id numbers):

local ContentProvider = Game:GetService("ContentProvider")
 
-- load a bunch of assets
local assets = {2253543, 2434541, 5133543, 2423433} --replace with your assets ids
ContentProvider:PreloadAsync(assets)
 
-- wait for them to complete
while ContentProvider.RequestQueueSize > 0 do
	wait(0.1)
end

basically stolen from wiki, modified to not use deprecated functions

More info: http://wiki.roblox.com/index.php?title=API:Class/ContentProvider

10 comments

0

Where would I add the wait(5)?

0

I am also getting the errors: 'Unable to cast to Array' after adding music:Play()

0

And I am still getting the error: 'ContentProvider:Preload() failed for rbxassetid://138499093 (x3)'

0

You should probably add the wait at the top so you can give time for the assets to load.

0

Also, rbxassetid://138499093 is not part of your assets table.

0

I know, but it prints that, and I am also getting the errors: 'Unable to cast to Array' after adding music:Play()

0

I edited my answer.

0

Now I am getting the error: 'Unable to cast double to Content' on line 5

0

you need the prefix

0

Then technically, his code is right because he used the prefix in his code.

This discussion is preserved as it was. New answers, comments, and votes are closed.