My old music script that played Christmas songs is playing multiple songs at a time. How do I prevent / fix this?
print('ran')
local musicholder = script.Parent
math.randomseed(tick());
local songList = {
musicholder:WaitForChild('CW'),
musicholder:WaitForChild('DeckDubstep'),
musicholder:WaitForChild('EhDe'),
musicholder:WaitForChild('JayKode'),
musicholder:WaitForChild('Ookay'),
musicholder:WaitForChild('SantaComes'),
musicholder:WaitForChild('XmasToMe'),
musicholder:WaitForChild('XmasBeats'),
--musicholder:WaitForChild('Song'),
--musicholder:WaitForChild('Song')
-- we wait for each song
-- add the rest of the songs to this list
}
local songCount = #songList -- this returns the number of items in the table above so we only change as little code as possible when adding songs
local played = {}; --// Create a table for played songs.
while true do
wait(7)
local songNum = math.random(1, songCount) -- gets a random number in the range of the number of songs
if played[songNum] then --// Check if the song has been played.
repeat songNum = math.random(songCount) until not played[songNum];
--// Choose a new song.
end;
played[songNum] = true; --// Record that this song has been played.
if #played == songCount then
played = {}; --// If all of them have been played, reset the table.
end;
print(songNum)
songList[songNum]:Play() -- we access the sound in the table and play it
songList[songNum].Ended:Wait() -- we wait until the song has finished then play anther song
end

1 comment
alright thanks but the issue i see with this is that the sound lengths are rounded and are very long decimals. ex. 34.41321321312312321321312312324567576465425234134143214324234234324234