I'm trying to make a random music player script. I'm adding more songs but here is what I've got for now. What do I have to fix and or what did I do wrong?
title = game.StarterGui.He.Box.Song function Playsong() local number = math.random(1,2) if number == 1 then script.Sound1:Play() title.Text = "Hate Me" wait(15) script.Sound1:Stop() title.Text = "No Song Playing" wait(3) title.Text = "Loading Song" wait(3) Playsong() else if number == 2 then script.Sound2:Play() title.Text = "Stitches" wait(120) script.Sound2:Stop() title.Text = "No Song Playing" wait(1) title.Text = "Loading Song" wait(1) Playsong() end end end Playsong()
Hello,
You've made mistakes on several lines so I will copy your Lua code and add corrections where you've gone wrong.
title = game.StarterGui.He.Box.Song -- Should be game.Players.LocalPlayer.PlayerGui.He.Box.Song function Playsong() local number = math.random(1,2) if number == 1 then script.Sound1:Play() title.Text = "Hate Me" wait(15) script.Sound1:Stop() title.Text = "No Song Playing" wait(3) title.Text = "Loading Song" wait(3) Playsong() else if number == 2 then -- 'Else if' doesn't exist. It's just 'elseif' script.Sound2:Play() title.Text = "Stitches" wait(120) script.Sound2:Stop() title.Text = "No Song Playing" wait(1) title.Text = "Loading Song" wait(1) Playsong() end end end Playsong()
If this answers your problem perfectly, then make sure to make this an accepted answer. If you have any questions also just comment them.