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

Music Player script not working?

Asked by 8 years ago

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

0
please put your code inside a code block to make it easier to read. ChemicalHex 979 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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
0
It worked, thank you. OneTruePain 191 — 8y
Ad

Answer this question