I have a script that plays music once a button is pressed, but I want to wait until the song that is playing is over and only then be able to click again and have another song play. How can I wait for the end of a song? Any and all help is appreciated.
Storage = game:GetService("ReplicatedStorage").SoundStorage
SoundTable = {Storage.OneDance, Storage.Freaks, Storage.Spaz, Storage.DontWorryChild, Storage.MonsterMash, Storage.Centuries}
-- Run numbers a different way.
function ChooseMusic(Table)
for i,v in pairs(Table) do
local x = math.random(1,#Table)
print(x)
if x == 1 then
local Sound = SoundTable[1]
local SoundClone = Sound:Clone()
SoundClone.Parent = workspace.Speaker
SoundClone:Play()
break
elseif x == 2 then
local Sound = SoundTable[2]
local SoundClone = Sound:Clone()
SoundClone.Parent = workspace.Speaker
SoundClone:Play()
break
elseif x == 3 then
local Sound = SoundTable[3]
local SoundClone = Sound:Clone()
SoundClone.Parent = workspace.Speaker
SoundClone:Play()
break
elseif x == 4 then
local Sound = SoundTable[4]
local SoundClone = Sound:Clone()
SoundClone.Parent = workspace.Speaker
SoundClone:Play()
break
elseif x == 5 then
local Sound = SoundTable[5]
local SoundClone = Sound:Clone()
SoundClone.Parent = workspace.Speaker
SoundClone:Play()
break
elseif x == 6 then
local Sound = SoundTable[6]
local SoundClone = Sound:Clone()
SoundClone.Parent = workspace.Speaker
SoundClone:Play()
break
end
end
end
script.Parent.ClickDetector.mouseClick:connect(function()
ChooseMusic(SoundTable)
end)
