I made a script to play music in the background of my game, and when a round starts, change the sound. But, it runs off of the status string value (the status value is what controls the bar at the top that shows players "Intermission", etc.) I feel like there is a more efficient way to do this. Also, how could I make a sort of playlist that plays a random song instead of just the one? Heres my script:
while true do game.Workspace.Wind:Stop() game.Workspace.BGM:Play() repeat wait (1) until game.ReplicatedStorage.Status.Value == "Start!" game.Workspace.BGM:Stop() game.Workspace.Wind:Play() repeat wait (1) until game.ReplicatedStorage.Status.Value == "Intermission" or game.ReplicatedStorage.Status.Value == "Waiting For More Players..." end
There is! Instead of useing a while loop function, you can use .Changed on the string value. Ill provide a quick snippet of code on how this could be used.
stringValue.Changed:Connect(function(newstring) if newstring == "Start!" then --Code when string = start here elseif newstring == "Intermission" then --Code when string = intermission here elseif newstring == "Waiting For More Players..." then --Code when string = waiting for players here end end)
With any further questions, feel free to reply to my answer.
To answer the second portion of your question, you can use a table to list all of the songs you have. I'm using a placeholder, "SONGIDHERE". You need to change them yourself.
songs = {SONGIDHERE,SONGIDHERE,SONGIDHERE} -- You could add more and more if you'd like. for i = 1,#songs do for i,v in pairs(game:GetDescendants()) do if v:IsA("Sound") then v:Stop() end end local song = Instance.new("Sound") song.Name = "song" song.SoundId = songs[i]
You can add a changed option to any other sound in the game. I've never searched through the descendant of game before, and I'm not sure if it's possible. If not, please comment on this post.