I'm making a GUI button where you click on it, and you have a shuffle list of music play. What I did was made a Button with a silent, muted "Audio" inside, and inside the "Audio" I added a script which is how it looks like;
math.randomseed(tick())
math.random() -- throw out first not-very-random value (known limitation of lua)
musicTable = --Making a table of music / your songs
{
"rbxassetid://142305080", -- 1 - Let's Groove
"rbxassetid://142386715", -- 2 - Can't Touch This
"rbxassetid://276873987", -- 3 - Noob Song
"rbxassetid://1100823134", -- 4 - At Dawn
"rbxassetid://142352014" -- 5 - Safety Dance
}
while true do
--Shuffle
local index = math.random(1, #musicTable - 1) -- choose an item not from the end
musicTable[1], musicTable[index] = musicTable[index], musicTable[1] -- switch with first item
for i = 2, #musicTable-1 do -- do regular shuffle algorithm starting at 2nd item
index = math.random(i, #musicTable)
musicTable[i], musicTable[index] = musicTable[index], musicTable[i]
end
--Play music
for i = 1, #musicTable do
wait(1) -- Just creating a small pause before a random song plays
script.Parent.SoundId = musicTable[i] --Choose song
script.Parent:Play() --Play song
script.Parent.Ended:wait() -- Waiting until the song has finished
end
end
The problem is when I click the GUI button it won't play the song playlist unless I toggle the Volume bar GUI that I also made. Whenever I unmute the "Audio" inside the GUI, the whole server starts playing music right when I join; even though I want it to only play when I click the GUI button. How do I make it so when you click the button it plays song immediately with sound by not having to toggle the Volume bar around and doesn't automatically play when I join server unless I click the GUI? Do I need to add some kind of a default volume to the script?

2 comments
Have you got the Volume of it above 0? If so, can you post the code to the volume script?
I did get volume above 0, as I said, it starts playing the music when I enter the server rather than when I click the button and this is the volume script.