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

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

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

2 comments

0

15 seconds is a pretty long wait, are you sure you waited that long for the next one to play?

0

Yes, I waited at least a few minutes.

1 answer

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

1 comment

0

Also, (1, #songs) is the same as (#songs).

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