I have a background music player in my game it shuffles through the music just fine but after all the songs are played the script stops playing the music here is my code:
wait(1)
while true do
local Sounds = script:GetChildren()
local RandomIndex = math.random(1,#Sounds)
local RandomSound = Sounds[RandomIndex]
RandomSound:Play()
RandomSound.Ended:Wait()
end
The music’s parent is the script in workspace btw, Thanks.
local Sounds = {0, 1, 2, 3, 4, 5, 6, -- Etc... Just add the AudioIds in here!}
local Sound = Sounds[math.random(1, #Sounds)]
local Player = Instance.new("Sound", workspace)
Player.Name = "Player"
while true do
local Sound = Sounds[math.random(1, #Sounds)]
Player.SoundId = Sound
Player:Play()
Player.Ended:Wait()
end
This should work, though I haven’t tested it.
Edit: Also, please add this script into either StarterGui, (for a client-based system), or ServerScriptService, (for a server-based system!)
I just got “Unable to assign property SoundId. Content expected, got nil” I tried to but it inside the brackets but it just gave me another error, Thanks.