Hello, a person has created a script which consists of when a player joins the game there is a music playing and after this music ends I would like another one to play but the problem with the script when a player joins the game and the first sound ends there is no music playing
here is the script
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.2 -- replace with the volume you'd like the song to be
local MuteImage, UnMuteImage = "rbxassetid://14327123642", "rbxassetid://14327004664"
local songmuted = false
local lastsongnumber = #musicfolder:GetChildren() - 1 -- don't change this
local function PreLoadMuteImages()
game:GetService("ContentProvider"):PreloadAsync({ MuteImage, UnMuteImage })
print("Done Loading")
end
coroutine.wrap(PreLoadMuteImages)()
local function mute()
print("attempt to toggle mute")
for i, v in pairs(musicfolder:GetChildren()) do
if v:IsA("Sound") then
if v.Volume ~= 0 then
songmuted = false
end
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 = MuteImage
songmuted = true
print("muted")
else
for i, v in pairs(musicfolder:GetChildren()) do
if v:IsA("Sound") then
if v.Volume == 0 then
v.Volume = songvolume
songmuted = false
end
end
end
button.Image = UnMuteImage
songmuted = true
print("unmuted")
end
end
local function changeSong()
if musicfolder:FindFirstChild("sound"..songnumber.Value) and songnumber.Value ~= lastsongnumber then
musicfolder:FindFirstChild("sound"..songnumber.Value+1):Play()
songnumber.Value += 1
print("next song: song "..songnumber.Value)
else
musicfolder:FindFirstChild("sound1"):Play()
songnumber.Value = 1
print("reached the end, restarting")
end
end
button.MouseButton1Down:Connect(mute)
for i, v in musicfolder:GetChildren() do
if v:IsA("Sound") then
v.Ended:Connect(changeSong)
end
end