So i’ve got this music script that randomly selects a song from the table given however i have a problem with destroying the sound instance after it is finished playing
This is my code, and the sound instance is not being destroyed, ive tried debrisservice and Destroy() to no avail. Any help on this issue would be very appreciated
local Music = script.Parent.Music
local DebrisService = game:GetService("Debris")
local AudioPart = script.Parent.AudioPart
local MusicTable = {}
local LastSong
for i , v in pairs(Music:GetChildren()) do
if v:IsA("Sound") then
table.insert(MusicTable , 1 , v)
end
end
print(MusicTable)
while true do
task.wait(5)
local randomSongSelection = MusicTable[math.random(1 , #MusicTable)]
local CloneSong = randomSongSelection:Clone()
CloneSong.Parent = AudioPart
CloneSong:Play()
CloneSong.Ended:Wait()
CloneSong.Ended:Connect(function()
DebrisService:AddItem(CloneSong , 1)
end)
task.wait(4)
end