I have a button in Workspace. Inside that button is a Click Detector, and a Sound. The Click Detector has a script inside it. I'm trying to make the script play songs on shuffle when the button is not pressed to change the song. I'm having trouble scripting this part, as I'm still learning how to script :) Any help would be greatly appreciated!!
The mouseclick function works perfectly and changes the song every 30 seconds when the button is pressed. The problem is the song shuffle part of the script. I'm trying to make it randomize the songs, as well as play them in random order until the button is pressed to change it.
local songs = {
"http://www.roblox.com/asset/?id=2206587324",
"http://www.roblox.com/asset/?id=4737555180",
"http://www.roblox.com/asset/?id=2231782710",
"http://www.roblox.com/asset/?id=2538961789",
"http://www.roblox.com/asset/?id=2538961789"
}
local songLength = #songs
local Sound = script.Parent.Parent.Sound
local CD = script.Parent
local randomGenerator = Random.new()
local selected = 0
Sound.Pitch = 1
Sound.Volume = 3
Sound.Name = "Player"
--------------------
----random songs play while button is not pressed
----song shuffle part of the script
---- not working
local song1 = "http://www.roblox.com/asset/?id=2206587324"
local song2 = "http://www.roblox.com/asset/?id=4737555180"
local song3 = "http://www.roblox.com/asset/?id=2538961789"
local song4 = "http://www.roblox.com/asset/?id=2538961789"
local song5 = "http://www.roblox.com/asset/?id=2538961789"
while (true) do
local track = (math.random(song1, song2, song3, song4, song5))
Sound:Play(track)
end
-------------------------
-------change song using button function
----this part works
enabled = true
CD.MouseClick:Connect(function()
if not enabled then
return
end
enabled = false
selected = randomGenerator:NextInteger(1, #songs)
local chosen = selected%#songs
if chosen == 0 then
chosen = #songs
end
print(chosen)
Sound.SoundId = songs[chosen]
Sound:Play()
Sound.Looped = true
wait(30)
enabled = true
end)

6 comments
didn't work. this also doesn't take into account the button part of the script, which changes the songs when its pressed :/
I didn't do the entire script for you. Just the queue generator. Also, what error does the script give?
I edited in the button script. How about now bro?
still doesnt work :(
What kind of error does it give though? I can't fix it if I don't know what's wrong with it, my friend.
it doesnt say anything in output :(