-- Decompiled with the Synapse X Luau decompiler.


local v1 = require(game.ReplicatedStorage:WaitForChild("Resources"));
while not v1.Loaded do
	game:GetService("RunService").Heartbeat:Wait();
end;
local u1 = {};
local u2 = {};
local u3 = Random.new();
local u4 = nil;
function Shuffle()
	local v2 = v1.Functions.CloneTable(u1);

		for v3, v4 in ipairs(u2) do
		if v3 then

		else
			break;
		end;

			for v6, v7 in ipairs(v2) do
			if v6 then

			else
				break;
			end;
			if v7 == v4 then
				table.remove(v2, v6);
				break;
			end;		
		end;	
	end;
	local v9 = v2[u3:NextInteger(1, #v2)];
	if not v9 then
		return;
	end;
	u4 = v1.Sound.PlayMusic(v9, 0.5, 4, nil, false);
	if 4 <= #u2 then
		table.remove(u2, 1);
	end;
	table.insert(u2, v9);
end;
function Clear()
	v1.Sound.StopMusic(1);
	u4 = nil;
	u2 = {};
end;
local u5 = nil;
function Set(p1)
	local v10 = v1.Directory.Worlds[p1];
	u1 = v10.music;
	Clear();
	if u5 then
		v1.Functions.Tween(u5, { 2 }, {
			Volume = 0
		}).Completed:Connect(function()
			u5:Stop();
			u5:Destroy();
		end);
	end;
	local l__ambience__11 = v10.ambience;
	if l__ambience__11 then
		if l__ambience__11 ~= 0 then
			u5 = v1.Sound.Play(l__ambience__11, script, 1, 0.3, nil, nil, true);
		end;
	end;
end;
v1.Signal.Fired("World Changed"):Connect(function(p2)
	Set(p2);
end);
task.defer(function()
	while true do
		if v1.Settings.MusicEnabled and #u1 > 0 then
			if not u4 or u4.TimeLength - 0.5 <= u4.TimePosition and u4.IsLoaded then
				Shuffle();
			end;
		elseif not v1.Settings.MusicEnabled and u4 then
			Clear();
		end;
		v1.Heartbeat(5);	
	end;
end);

