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!!
it keeps saying - Script timeout: exhausted allowed execution time
local songs = {
"http://www.roblox.com/asset/?id=142296509",
"http://www.roblox.com/asset/?id=154824158",
"http://www.roblox.com/asset/?id=142677206",
"http://www.roblox.com/asset/?id=166247544",
"http://www.roblox.com/asset/?id=155603984",
}
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"
buttonpr = false
enabled = true
while not buttonpr do
selected = randomGenerator:NextInteger(1, #songs)
local chosen = (selected/#songs)
chosen = #songs
Sound.SoundId = songs[chosen]
Sound:Play()
end
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
Sound:Stop()
end
print(chosen)
Sound.SoundId = songs[chosen]
Sound:Play()
Sound.Looped = true
buttonpr = true
wait(30)
buttonpr = false
enabled = true
end
)

5 comments
Wait so you want to randomize the songs played but still keep the same looping feature?
Why not just shuffle your table?
i want to randomize the order the songs play so each time you join a game its different
yea so do a Game.Players.PlayerAdded then connect it to a function then do the random thing in the function.
i want the music to play from the part the script is in, which is button, and also not interfere with how the button functions and changes the song