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

How do you make a back button for a music gui?

Asked by 2 years ago
Edited 2 years ago

Hello, basically im trying to make a song gui for a game, but I want to make a back button and its not working. This is my most recent script, and it goes back, but when the song stop it skips 2 songs ahead in the list. I have an idea why, but I dont know how to fix it. If you can, big thanks to you.

local MarketPlaceService = game:GetService("MarketplaceService")

local Songs = {
    4868000543, 
    5546935111, 
    840096159, 
    12345 
}

local globali = 1
local volume = .5

local SongObject = script.Parent.Song
local menu = script.Parent["Music Menu"]
local SongLabel = menu["Currently Playing"]
local SkipButton = menu["Skip Button Music"]
local MuteButton = menu["Mute Music"]
local VolumeUp = menu["Increase Volume Music"]
local VolumeDown = menu["Lower Volume Music"]
local BackwardsButton = menu["Back Button Music"]

MuteButton.MouseButton1Click:Connect(function()
    if SongObject.Volume > 0 then
        SongObject.Volume = 0
    else
        SongObject.Volume = volume
    end
end)

SkipButton.MouseButton1Click:Connect(function()
    SongObject:Stop()
end)

VolumeUp.MouseButton1Click:Connect(function()
    volume = volume + .1
    SongObject.Volume = volume
    print(volume)
end)

VolumeDown.MouseButton1Click:Connect(function()
    volume = volume - .1
    SongObject.Volume = volume
    print(volume)
end)

BackwardsButton.MouseButton1Click:Connect(function()
    local songid = string.gsub(SongObject.SoundId, "rbxassetid://", "")
    local numsong = tonumber(songid)
    local finding = table.find(Songs, numsong)
    local findform 
    findform = finding - 1
    local sing = Songs[findform]
    SongObject.SoundId = "rbxassetid://" .. sing
    SongObject:Play()
end)

while true do
    for i = 1, #Songs do
        local Song = Songs[i]
        print(i)
        local SongInfo = MarketPlaceService:GetProductInfo(Song)
        SongObject.SoundId = "rbxassetid://" .. Song
        SongObject:Play()
        SongLabel.Visible = true
        SongLabel.Text = SongInfo.Name
        wait(3)
        SongLabel.Visible = false
        repeat wait() until not SongObject.IsPlaying
    end
end

Edit: Had to fix some things that were messed up in my post, the post should be good now.

1 answer

Log in to vote
0
Answered by 2 years ago

Solved it! I had to remake the sound system so it would work, but it works. The script is below and open source for anyone who wants it.

local MarketPlaceService = game:GetService("MarketplaceService")

local Songs = {
    4868000543, 
    5546935111, 
    840096159, 
    12345 
}

local position = 0
local volume = .5

local SongObject = script.Parent.Song
local menu = script.Parent["Music Menu"]
local SongLabel = menu["Currently Playing"]
local SkipButton = menu["Skip Button Music"]
local MuteButton = menu["Mute Music"]
local VolumeUp = menu["Increase Volume Music"]
local VolumeDown = menu["Lower Volume Music"]
local BackwardsButton = menu["Back Button Music"]

MuteButton.MouseButton1Click:Connect(function()
    if SongObject.Volume > 0 then
        SongObject.Volume = 0
    else
        SongObject.Volume = volume
    end
end)

SkipButton.MouseButton1Click:Connect(function()
    SongObject:Stop()
end)

VolumeUp.MouseButton1Click:Connect(function()
    volume = volume + .1
    SongObject.Volume = volume
    print(volume)
end)

VolumeDown.MouseButton1Click:Connect(function()
    volume = volume - .1
    SongObject.Volume = volume
    print(volume)
end)

BackwardsButton.MouseButton1Click:Connect(function()
    position = position - 2
    SongObject:Stop()

end)

while true do
    if not SongObject.IsPlaying then
        position = position + 1 
        if position > #Songs then
            position = 1
        elseif position < 1 then
            position = #Songs
        end
        local song = Songs[position]
        local asset = game.MarketplaceService:GetProductInfo(song) -- Gets the sound's info
        SongObject.SoundId = "rbxassetid://".. song
        SongObject:Play()
        SongLabel.Text = asset.Name
            repeat wait() until not SongObject.IsPlaying
    end
end
Ad

Answer this question