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

MP3 Player Script Will Play The First Song When You Click Next But Not The Second, Any Help?

Asked by
LuaDLL 253 Moderation Voter
7 years ago

So when I click the next button on it it will play the first time but when I click it again it will not play the next song.

Error: Players.FuriaI.PlayerGui.mp3player.BackGround.Main:69: bad argument #2 to 'random' (interval is empty) 09:13:23.975 - Stack Begin 09:13:23.976 - Script 'Players.FuriaI.PlayerGui.mp3player.BackGround.Main', Line 69 - global NextSong 09:13:23.977 - Script 'Players.FuriaI.PlayerGui.mp3player.BackGround.Main', Line 81 Script:

01local Player = game.Players.LocalPlayer
02repeat wait() until Player.Character
03local Character = Player.Character
04local Bg = script.Parent
05local Bar = Bg.Bar
06local PlayPause = Bg.PlayPause
07local Prev = Bg.Prev
08local Next = Bg.Next
09local SongImg = Bg.ImageLabel
10local Song = Bg.Song
11local Time = Bg.Time
12local SongIsPlaying = false
13 
14local SoundIds = {
15    897623161,844906598,
View all 96 lines...

1 answer

Log in to vote
0
Answered by 7 years ago

This might be my fault, in part, for giving a lackluster answer yesterday :p

When you pick a song, your ChosenSong, you remove the song from the array SoundIds. After a couple of removals, there are no ids left in SoundIds, so #SoundIds returns 0. math.Random(1, 0) errors because (1, 0) is an invalid interval. Think about a jukebox; to play a new song, you have to remove the record on the table and choose a new one.

Try adding the song back into SoundIds when you change songs. Something like:

1table.insert(SoundIds, ChosenSong[1]);
2ChosenSong = {};
3-- table.insert(table, value) inserts value at the end of table, so pick an index between the first and second to last values (don't repeat the song)
4local index = math.Random(1, #SoundIds - 1)
5table.insert(ChosenSong, SoundIds[index]);
6table.remove(SoundIds, index);
0
Thank you man! LuaDLL 253 — 7y
0
You're welcome! :) KidTech101 376 — 7y
Ad

Answer this question