Lobby Music Rotation Script not working

I made a script to rotate lobby music thrice and then swap a song, a long with a gui text. All music is stored in workspace.Music and my GUI is properly in the startergui. This is my script, any help is appreciated.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("Songslist"):WaitForChild("Songs")
local song1 = workspace.Music:FindFirstChild("Time")
local song2 = workspace.Music:FindFirstChild("Solaris")
local song3 = workspace.Music:FindFirstChild("Flowers")
local song4 = workspace.Music:FindFirstChild("Annoying")

local currentSong = song1 -- Set an initial song

while true do
    if currentSong == song1 and currentSong.IsPlaying then
        gui.Text = "Now Playing - Drifting Time Misplaced (8-BIT EDITION)"
        wait(497.232)
        currentSong:Stop()
        currentSong = song2
        currentSong:Play()
    elseif currentSong == song2 and currentSong.IsPlaying then
        gui.Text = "Solaris Daylight (Ray's Mod Edition)"
        wait(357.213)
        currentSong:Stop()
        currentSong = song3
        currentSong:Play()
    elseif currentSong == song3 and currentSong.IsPlaying then
        gui.Text = "Now playing - OMORI, A Home for Flowers"
        wait(278.91)
        currentSong:Stop()
        currentSong = song4
        currentSong:Play()
    elseif currentSong == song4 and currentSong.IsPlaying then
        gui.Text = "Now playing - OMORI, Whale Whale Whale"
        wait(221.865)
        currentSong:Stop()
        currentSong = song1
        currentSong:Play()
    end

    wait(1)
end

By the way, I multiplied the song length by three for the wait time.
All audios work but my script doesn’t and doesn’t return anything in console. Again, help is appreciated.

1 Like

youre checking if the currentsong is playing in the if statements, play the currentsong before the while loop

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("Songslist"):WaitForChild("Songs")
local Music = workspace:WaitForChild("Music")
local Songs = Music:GetChildren()

Music.ChildAdded:Connect(function(sound : Sound)
    table.insert(Songs, sound)
end)

while true do
    for i,v : Sound in Songs do
        local data = v.IsLoaded and game:GetService("MarketplaceService"):GetProductInfo(v.SoundId) or nil

        if data then
            gui.Text = `Now Playing - {data.Name}`
            v:Play()
            v.Ended:Wait()
        end
    end
    task.wait()
end

image
I received this strange error. I ran through the script and it seems totally fine.

what script did you run? I dont see how that’s possible because workspace exists off of runstart

the script is in workspace so you probably made a serverscript instead of a localscript, serverscripts dont have a localplayer so thats why its erroring on line 3

1 Like

everything that i did so far ran off of a script in workspace named Music
image


image
seperated images
image

so does it work or did I mess up

No, it doesn’t work and it errors me in console with “Attempted to index nil in line 3” about the player gui or something… This is really confusing.

I can’t fix that you need to grab the path yourself

1 Like