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

Why does my music script only play one song then stop?

Asked by
dcaa77 0
4 years ago

Hello, I am trying to make a script that shuffles songs randomly. My issue is that it only plays one song then stops. Thanks in advance.

Songs = game.SoundService.Music:GetChildren()

while true do
    ChosenSong = Songs[math.random(1,#Songs)]
    print(ChosenSong.Name)
    ChosenSong:Play()
    ChosenSong.Ended:Wait()
    wait(15)
end
0
15 seconds is a pretty long wait, are you sure you waited that long for the next one to play? Nickuhhhhhhhhhhhhhhh 834 — 4y
0
Yes, I waited at least a few minutes. dcaa77 0 — 4y

1 answer

Log in to vote
0
Answered by
dcaa77 0
4 years ago

I figured it out! The script needed to be a local script in the player. I also made the variables local and added a SoundService variable. Here's the updated script:

local SoundService = game:GetService("SoundService")
local Songs = SoundService:WaitForChild("Music"):GetChildren()
game.Players.LocalPlayer.CharacterAppearanceLoaded:Wait()
while true do
    local ChosenSong = Songs[math.random(1,#Songs)]
    ChosenSong:Play()
    ChosenSong.Ended:Wait()
end
0
Also, (1, #songs) is the same as (#songs). dcaa77 0 — 4y
Ad

Answer this question