Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How shall I fix this Music Player script?

Asked by
awfulszn 394 Moderation Voter
6 years ago
Edited 6 years ago

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
0
You can't fix this. It is like asking "How can I prevent my internet from having glitches?" hiimgoodpack 2009 — 6y
0
It's an error with the ROBLOX core scripts. BennyBoiOriginal 293 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
Where would I add the wait(5)? awfulszn 394 — 6y
0
I am also getting the errors: 'Unable to cast to Array' after adding music:Play() awfulszn 394 — 6y
0
And I am still getting the error: 'ContentProvider:Preload() failed for rbxassetid://138499093 (x3)' awfulszn 394 — 6y
0
You should probably add the wait at the top so you can give time for the assets to load. BennyBoiOriginal 293 — 6y
View all comments (6 more)
0
Also, rbxassetid://138499093 is not part of your assets table. BennyBoiOriginal 293 — 6y
0
I know, but it prints that, and I am also getting the errors: 'Unable to cast to Array' after adding music:Play() awfulszn 394 — 6y
0
I edited my answer. BennyBoiOriginal 293 — 6y
0
Now I am getting the error: 'Unable to cast double to Content' on line 5 awfulszn 394 — 6y
0
you need the prefix hiimgoodpack 2009 — 6y
0
Then technically, his code is right because he used the prefix in his code. BennyBoiOriginal 293 — 6y
Ad

Answer this question