So I'm trying to create a simple music system for my game, here's how it works.
local Sound1 = script.Parent.Sound1
local Sound2 = script.Parent.Sound2
local Sound3 = script.Parent.Sound3
while wait(1) do --Plays music
local Music = math.random(1,3)
if Sound1.Playing == false and Sound2.Playing == false and Sound3.Playing == false then --if theres no music playing then
if Music == 1 then
Sound1:Play()
if Music == 2 then
Sound2:Play()
if Music == 3 then
Sound3:Play()
end
end
end
end
end
First, I got all the "Sound" values. Then I made a while wait() loop. I then did math.random to randomize which music would play (1,3). I then made an "if" statement saying that if the music isn't playing then use the math.random values that were originally created in order to figure out which sound to play. Please no useless comments, anything simple like "else" statements I've already tried, so no one word can fix it. Thank you!

1 comment
I forgot the problem in my post, the problem is that the script works, however, whenever the first song stops, it doesn't loop and start another song. Sorry about that!