Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Music-player GUI no longer playing music?

Asked by 1 year ago

A (possibly outdated?) GUI I have used to play music from a playlist. Recently the script hasn't been functioning(as in music does not play) and I'm not quite sure why. Script for the GUI:

local CurrentSong = script:WaitForChild("CurrentSong")
local Playlist = script:WaitForChild("Playlist")
local gui = script.Parent
local MainFrame = script.Parent.SwitchTeam.MainFrame1
local MuteButton = MainFrame:WaitForChild("Mute")
local Songs = {}
for _, child in pairs(Playlist:GetChildren()) do
    table.insert(Songs, child.Value)
end

local songNumber = math.random(1, #Songs)
local nextSong = function()
    if CurrentSong.IsPlaying then
        CurrentSong:Stop()
    end
    songNumber = songNumber + 1
    if songNumber > #Songs then
        songNumber = 1
    end
    CurrentSong.SoundId = Songs[songNumber]
    CurrentSong.TimePosition = 0
    CurrentSong:Play()
end

CurrentSong.Ended:Connect(nextSong)

-- Start music
nextSong()

MuteButton.MouseButton1Down:Connect(function()
    if CurrentSong.Volume ~= 0 then
        CurrentSong.Volume = 0
        MuteButton.Text = "Unmute Music"
    else
        MuteButton.Text = "Mute Music"
        CurrentSong.Volume = 0.5
    end
end)

The mute button does change texts when clicked (obviously I cannot verify if it works anymore because music does not play), however the script WAS functional.

0
Are any errors being logged? DindinYT37 246 — 1y
0
No errors. It just seems to be no longer functional. I'm wondering if it's outdated, but I have no idea. satrasatra 8 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

EDIT: Try using NumberValues instead. Inside each NumberValue are the song ids.

And try waiting for the sound to load first before playing it.

local CurrentSong = script:WaitForChild("CurrentSong")
local Playlist = script:WaitForChild("Playlist")
local gui = script.Parent
local MainFrame = script.Parent:WaitForChild("SwitchTeam").MainFrame1
local MuteButton = MainFrame:WaitForChild("Mute")

local SongIds = {}
for _, child in ipairs(Playlist:GetChildren()) do
    if child:IsA("NumberValue") then
        table.insert(Songs, child.Value)
    end
end

local function loadSound(sound: Sound)
    if not sound.IsLoaded then
        sound.Loaded:Wait()
    end
end

local songNumber = math.random(1, #SongIds)
local function nextSong()
    if CurrentSong.IsPlaying then
        CurrentSong:Stop()
    end

    songNumber += 1
    if songNumber > #SongIds then
        songNumber = 1
    end

    CurrentSong.TimePosition = 0
    CurrentSong.SoundId = "rbxassetid://" .. SongIds[songNumber]
    loadSound(CurrentSound)
    CurrentSong:Play()
end

CurrentSong.Ended:Connect(nextSong)

-- Start music
nextSong()

MuteButton.MouseButton1Down:Connect(function()
    if CurrentSong.Volume ~= 0 then
        CurrentSong.Volume = 0
        MuteButton.Text = "Unmute Music"
    else
        MuteButton.Text = "Mute Music"
        CurrentSong.Volume = 0.5
    end
end)

--

It's probably because of Roblox removing every audio in the Marketplace back in March 2022. This made uploading audios free but the person who uploaded the audio can only be used in their game. You can also give permission to a game to use your audio but it will also need the developer's permission.

What you can do is replace the audios you're using with the public audios (mostly uploaded by Roblox and some music companies) in the Marketplace such as Life in an Elevator (rbxassetid://1841647093) and the classic Raining Tacos (rbxassetid://142376088).

0
All audios are made by me, but that could have something to do with it, since the audios are values that are inserted into a sound for the playlist to work. I'll try and find a work-around where I can just use my audios and not have them as values. Thanks, though! satrasatra 8 — 1y
0
are your values numbers or strings? T3_MasterGamer 2189 — 1y
0
did you upload your audios before or after march 2022? just confirming T3_MasterGamer 2189 — 1y
0
After march of 2022. And the values are strings, not numbers. satrasatra 8 — 1y
View all comments (4 more)
0
there i edited it T3_MasterGamer 2189 — 1y
0
in the new NumberValues, make the value the song id. T3_MasterGamer 2189 — 1y
0
for example, i assume your string either look like "http://www.roblox.com/asset/?id=9120386436" or "rbxassetid://9120386436" T3_MasterGamer 2189 — 1y
0
what you will do is take the number, which is 9120386436 in our example, and paste it to the value of the numbervalue T3_MasterGamer 2189 — 1y
Ad

Answer this question