First step is for you to upload both of those images to Roblox, unless you already have
After that, here’s the script I wrote:
local musicfolder = game.Workspace:WaitForChild("songs") -- place a folder into workspace. Add three UNLOOPED sounds into the folder named "sound1", "sound2", and "sound3".
-- Set only sound1's isPlaying property to true
local songnumber = musicfolder.song -- insert an intvalue into the folder called "song". Set the value to 1
local button = script.Parent
local songvolume = 0.8 -- replace with the volume you'd like the song to be
local songmuted = false
local function mute()
for i, v in pairs(musicfolder:GetChildren()) do
if v.Playing == true then
v.Playing = false
songmuted = false
end
end
if songmuted == false then
for i, v in pairs(musicfolder:GetChildren()) do
if v:IsA("Sound") then
v.Volume = 0
end
end
button.Image = "unmuteimageid" -- replace with the imageid
else
local songtoplay = musicfolder:FindFirstChild("sound"..songnumber.Value)
if songtoplay == nil then return end
songtoplay.Volume = songvolume
button.Image = "muteimageid"
end
end
local function changeSong()
if songnumber.Value == 1 then
musicfolder.sound2:Play()
songnumber.Value = 2
else
if songnumber.Value == 2 then
musicfolder.sound3:Play()
songnumber.Value = 3
else
if songnumber.Value == 3 then
musicfolder.sound1:Play()
songnumber.Value = 1
end
end
end
end
button.MouseButton1Down:Connect(mute)
musicfolder.sound1.Ended:Connect(changeSong)
musicfolder.sound2.Ended:Connect(changeSong)
musicfolder.sound3.Ended:Connect(changeSong)
It’s pretty scrappy and requires some setup. I think it works, but if not here are some alternative’s could be these systems:
Hey this script looks pretty good, but I’m going to recommend some changes if thats ok.
First I want to add a PreloadAsync() as the player will notice the change from the mute to an unmute button if you don’t Preload it. Also I don’t like how the ChangeSound function is set up. So I am gonna change that up a bit. You only allowed for 3 songs, but we can add a couple more lines and make them work for as many songs (saves time from coding more, and is more effective in what it does)
local musicfolder = game.Workspace:WaitForChild("songs") -- place a folder into workspace. Add three UNLOOPED sounds into the folder named "sound1", "sound2", and "sound3".
-- Set only sound1's isPlaying property to true
local songnumber = musicfolder.song -- insert an intvalue into the folder called "song". Set the value to 1
local button = script.Parent
local songvolume = 0.8 -- replace with the volume you'd like the song to be
local MuteImage, UnMuteImage = "muteimageid", "unmuteimageid"
local songmuted = true
local function PreLoadMuteImages()
game:GetService("ContentProvider"):PreloadAsync({ MuteImage, UnMuteImage })
print("Done Loading")
end
coroutine.wrap(PreLoadMuteImages)()
local function mute()
for i, v in pairs(musicfolder:GetChildren()) do
if v.Playing == true then
v.Playing = false
songmuted = false
end
end
if songmuted == false then
for i, v in pairs(musicfolder:GetChildren()) do
if v:IsA("Sound") then
v.Volume = 0
end
end
button.Image = UnMuteImage
else
local songtoplay = musicfolder:FindFirstChild("sound"..songnumber.Value)
if songtoplay == nil then return end
songtoplay.Volume = songvolume
button.Image = MuteImage
end
end
local function changeSong()
if musicfolder:FindFirstChild("sound"..songnumber.Value + 1) then
musicfolder:FindFirstChild("sound"..songnumber.Value + 1):Play()
songnumber.Value += 1
else
musicfolder:FindFirstChild("sound1"):Play()
songnumber.Value = 1
end
end
button.MouseButton1Down:Connect(mute)
for i, v in musicfolder:GetChildren() do
if v:IsA("Sound") then
v.Ended:Connect(changeSong)
end
end
I was wondering how to optimize the code for future expansion of the song selection but your change in that regard fixes the problem.
Also, I’ll do some research into PreloadAsync() so I can start utilizing it in the future. I hope that with these improvements the script could be useful to @Capitain_Lefty.
Also your using the Numbers as the images, and not a rbxassetid format… Throw those numbers, in a image label, it should spilt out a ‘almost link like’ link, and copy that, and insert it into the images. It should look something like rbxassetid://NUMBERSHERE
Sorry a mistake I made that is visible on line vingt-huit was forgetting to set songmuted to true, so start a new line there which states songmuted = true