local o=game:GetService("\083\111\117\110\100\083\101\114\118\105\099\101")local v=script.Parent.Parent.Parent.Parent local Y=require(v.Parent.Knit)local O=(require(v.Config)).Config local R={Name="\077\117\115\105\099\083\101\114\118\105\099\101";Client={CurrentSong=Y.CreateProperty()};CurrentIndex=0,Songs=O.Systems.Music.SoundGroup:GetChildren()}function R.PlayNextSong(v)if v.CurrentEndConnection then v.CurrentEndConnection:Disconnect()v.CurrentEndConnection=nil end if v.SongCopy then v.SongCopy:Destroy()end v.Client.CurrentSong:Set(nil)v.CurrentIndex+=1 if not v.Songs[v.CurrentIndex]then v.CurrentIndex=1 end v.CurrentSong=v.Songs[v.CurrentIndex]if v.CurrentSong then v.Client.CurrentSong:Set(v.CurrentSong)v.SongCopy=v.CurrentSong:Clone()v.SongCopy.Parent=o v.SongCopy.Volume=0 v.SongCopy:Play()v.CurrentEndConnection=v.SongCopy.Ended:Connect(function()v:PlayNextSong()end)end end function R.KnitStart(o)o:PlayNextSong()end for o,v in ipairs(R.Songs)do if not v:IsA("\083\111\117\110\100")then v:Destroy()end v.Looped=false v.PlayOnRemove=false v.Playing=false end return R
local SoundService = game:GetService("SoundService")

local Rorooms = script.Parent.Parent.Parent.Parent
local Knit = require(Rorooms.Parent.Knit)
local Config = require(Rorooms.Config).Config

local MusicService = {
	Name = "MusicService",
	Client = {
		CurrentSong = Knit.CreateProperty(),
	},

	CurrentIndex = 0,
	Songs = Config.Systems.Music.SoundGroup:GetChildren(),
}

function MusicService:PlayNextSong()
	if self.CurrentEndConnection then
		self.CurrentEndConnection:Disconnect()
		self.CurrentEndConnection = nil
	end
	if self.SongCopy then
		self.SongCopy:Destroy()
	end
	self.Client.CurrentSong:Set(nil)

	self.CurrentIndex += 1
	if not self.Songs[self.CurrentIndex] then
		self.CurrentIndex = 1
	end

	self.CurrentSong = self.Songs[self.CurrentIndex]
	if self.CurrentSong then
		self.Client.CurrentSong:Set(self.CurrentSong)
		self.SongCopy = self.CurrentSong:Clone()
		self.SongCopy.Parent = SoundService
		self.SongCopy.Volume = 0
		self.SongCopy:Play()
		self.CurrentEndConnection = self.SongCopy.Ended:Connect(function()
			self:PlayNextSong()
		end)
	end
end

function MusicService:KnitStart()
	self:PlayNextSong()
end

for _, Song in ipairs(MusicService.Songs) do
	if not Song:IsA("Sound") then
		Song:Destroy()
	end
	Song.Looped = false
	Song.PlayOnRemove = false
	Song.Playing = false
end

return MusicService
