Hey, i want to make simple play/stop music gui, but it play only one music from the list. I don't know what should i use here? I thought for loop is all what i needed, but i guess it need something more.
Script:
local sound = script.Parent.Parent.PlayableSound local musicList = script.Parent.MusicList for _, music in pairs(musicList:GetChildren()) do sound.SoundId = "rbxassetid://".. music.Value sound:Play() end
Gui screenshot: https://gyazo.com/37911080a1bfe0fc192005acc1483104
SoundID is NumberValue. Maybe i need to rename SoundID to 1, 2, 3 etc. ?
Basically it loops so fast through all the sounds, and you don't hear any of them until the loop ends and it plays the last song.
Just wait inside the loop for the sound to end. You can only do this in a Local Script
.
--// Local Script: local sound = script.Parent.Parent.PlayableSound local musicList = script.Parent.MusicList for _, music in pairs(musicList:GetChildren()) do sound.SoundId = "rbxassetid://".. music.Value sound:Play() sound.Ended:Wait() -- Wait for the sound to end. end
Edit:
As for making it random, you need to use math.random().
You can index a table using a number to get a direct value within the table. Using math.random, and getting the size of the table using #table, we can get a random music.
--// Local Script: local sound = script.Parent.Parent.PlayableSound local musicList = script.Parent.MusicList:GetChildren() while true do local music = musicList[math.random(#musicList)] -- Random Music sound.SoundId = "rbxassetid://".. music.Value sound:Play() sound.Ended:Wait() -- Wait for the sound to end. end