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

Music Player script not working?

So I made my own custom music player script that is suppose to play a random song from a list after the first song ends, however what ends up happening is it'll play one song, then about 2 seconds or so later it'll start another song and keep going. Eventually it's playing all the possible songs at once. I used a ServerScript that runs a loop inside a spawnbox model.

songs = {222607140, 221660385, 149318510, 163357343, 148620885} sound = script.Sound while true do rsong = math.random(1#,songs) song = songs[rsong] sound2 = sound:clone().Parent = script.Parent sound2.SoundId = ("rbxassetid://"..song) wait(sound2.TimeLength) sound:Destroy() end

1 comment

0

please put your code inside a code block to make it easier to read.

1 answer

✓ Accepted answer

You're not stopping the sound before you destroy it. Try using sound:Pause() or sound:Stop() before killing it.

songs = {222607140, 221660385, 149318510, 163357343, 148620885}
 sound = script.Sound 
while true do 
rsong = math.random(1#,songs)
 song = songs[rsong] 
sound2 = sound:clone().Parent = script.Parent
 sound2.SoundId = ("rbxassetid://"..song) 
wait(sound2.TimeLength) 
sound:Stop()
sound:Destroy()
 end

1 comment

0

It worked, thank you.

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