local t=require(script.Parent.Settings)if t.UseGlobalBackgroundMusic==false and t.UseMusicZones==false then error("\067\105\110\100\101\114\105\110\103\'\115 \066\071\077 \101\114\114\111\114\058 \089\111\117 \104\097\118\101 \100\105\115\097\098\108\101\100 \098\111\116\104 \071\108\111\098\097\108 \066\097\099\107\103\114\111\117\110\100 \077\117\115\105\099 \097\110\100 \077\117\115\105\099 \090\111\110\101\115\046 \089\111\117 \109\117\115\116 \099\104\097\110\103\101 \097\116 \108\101\097\115\116 \111\110\101 \111\102 \116\104\101\115\101 \115\101\116\116\105\110\103\115 \116\111 \'\116\114\117\101\'\046")return end local o="\091\049\093 \071\108\111\098\097\108 \066\097\099\107\103\114\111\117\110\100 \077\117\115\105\099"local n="\091\050\093 \066\097\099\107\103\114\111\117\110\100 \077\117\115\105\099 \090\111\110\101\115"local P=Instance.new("\070\111\108\100\101\114")P.Name="\067\105\110\100\101\114\105\110\103\066\071\077"script.Parent.Settings.Parent=P script.LocalBackgroundMusic.Parent=game.StarterPlayer.StarterPlayerScripts local b=Instance.new("\070\111\108\100\101\114")local d=Instance.new("\070\111\108\100\101\114",b)d.Name="\077\117\115\105\099\090\111\110\101\115"local M=Instance.new("\070\111\108\100\101\114",b)M.Name="\071\108\111\098\097\108\077\117\115\105\099"if t.UseMusicZones==true then local t=script.Parent:FindFirstChild(n)or game.ReplicatedStorage:FindFirstChild(n)or workspace:FindFirstChild(n)or game:FindFirstChild(n,true)if t then for t,o in pairs(t:GetChildren())do if o:IsA("\077\111\100\101\108")and o:FindFirstChild("\077\117\115\105\099")then o.Parent=d end end else error("\067\105\110\100\101\114\105\110\103\'\115 \066\071\077 \101\114\114\111\114\058 \089\111\117\114 \098\097\099\107\103\114\111\117\110\100 \109\117\115\105\099 \122\111\110\101\115 \102\111\108\100\101\114 \099\111\117\108\100 \110\111\116 \098\101 \102\111\117\110\100\033 \089\111\117 \109\097\121 \104\097\118\101 \100\101\108\101\116\101\100\047\114\101\110\097\109\101\100 \116\104\101 \111\114\105\103\105\110\097\108 \102\111\108\100\101\114\046 \073\116 \115\104\111\117\108\100 \098\101 \110\097\109\101\100\058 "..n)return end end if t.UseGlobalBackgroundMusic==true then local t=script.Parent:FindFirstChild(o)or game.ReplicatedStorage:FindFirstChild(o)or workspace:FindFirstChild(o)or game:FindFirstChild(o,true)if t then for t,o in pairs(t:GetChildren())do if o:IsA("\083\111\117\110\100")then o.Parent=M end end else error("\067\105\110\100\101\114\105\110\103\'\115 \066\071\077 \101\114\114\111\114\058 \089\111\117\114 \103\108\111\098\097\108 \098\097\099\107\103\114\111\117\110\100 \109\117\115\105\099 \102\111\108\100\101\114 \099\111\117\108\100 \110\111\116 \098\101 \102\111\117\110\100\033 \089\111\117 \109\097\121 \104\097\118\101 \100\101\108\101\116\101\100\047\114\101\110\097\109\101\100 \116\104\101 \111\114\105\103\105\110\097\108 \102\111\108\100\101\114\046 \073\116 \115\104\111\117\108\100 \098\101 \110\097\109\101\100\058 "..o)return end end if t.UseGlobalBackgroundMusic==true and#M:GetChildren()==0 then warn("\067\105\110\100\101\114\105\110\103\'\115 \066\071\077 \119\097\114\110\105\110\103\058 \089\111\117\114 \103\108\111\098\097\108 \098\097\099\107\103\114\111\117\110\100 \109\117\115\105\099 \102\111\108\100\101\114 \105\115 \099\111\109\112\108\101\116\101\108\121 \101\109\112\116\121\059 \110\111 \109\117\115\105\099 \119\105\108\108 \098\101 \112\108\097\121\101\100 \102\114\111\109 \116\104\101\114\101\046")end if t.UseMusicZones==true and#d:GetChildren()==0 then warn("\067\105\110\100\101\114\105\110\103\'\115 \066\071\077 \119\097\114\110\105\110\103\058 \089\111\117\114 \098\097\099\107\103\114\111\117\110\100 \109\117\115\105\099 \122\111\110\101\115 \102\111\108\100\101\114 \105\115 \099\111\109\112\108\101\116\101\108\121 \101\109\112\116\121\059 \110\111 \109\117\115\105\099 \119\105\108\108 \098\101 \112\108\097\121\101\100 \102\114\111\109 \116\104\101\114\101\046")end b.Name="\077\117\115\105\099\070\111\108\100\101\114"b.Parent=P local h=0 function recurse(t)for t,o in pairs(t:GetChildren())do h=h+1 recurse(o)end end recurse(b)local I=Instance.new("\073\110\116\086\097\108\117\101",P)I.Name="\079\098\106\101\099\116\067\111\117\110\116"I.Value=h P.Parent=game.ReplicatedStorage script.Parent:Destroy()
--[[
	
	When the game is run, this script automatically places all of the model's contents into the correct locations and deletes any leftover clutter.
	
	All you have to do is configure the music IDs and/or zones as described in the README - the rest will be automatically handled! 
	
--]]

local settings = require(script.Parent.Settings)

if settings.UseGlobalBackgroundMusic == false and settings.UseMusicZones == false then
	error(
		"Cindering's BGM error: You have disabled both Global Background Music and Music Zones. You must change at least one of these settings to 'true'."
	)
	return
end

local name1 = "[1] Global Background Music"
local name2 = "[2] Background Music Zones"

local container = Instance.new("Folder")
container.Name = "CinderingBGM"

script.Parent.Settings.Parent = container

script.LocalBackgroundMusic.Parent = game.StarterPlayer.StarterPlayerScripts

local music = Instance.new("Folder")
local zones = Instance.new("Folder", music)
zones.Name = "MusicZones"
local global = Instance.new("Folder", music)
global.Name = "GlobalMusic"

if settings.UseMusicZones == true then
	local folder = script.Parent:FindFirstChild(name2)
		or game.ReplicatedStorage:FindFirstChild(name2)
		or workspace:FindFirstChild(name2)
		or game:FindFirstChild(name2, true) -- never know where someone might accidentally drag that folder...

	if folder then
		for _, model in pairs(folder:GetChildren()) do
			if model:IsA("Model") and model:FindFirstChild("Music") then
				model.Parent = zones
			end
		end
	else
		error(
			"Cindering's BGM error: Your background music zones folder could not be found! You may have deleted/renamed the original folder. It should be named: "
				.. name2
		)
		return
	end
end

if settings.UseGlobalBackgroundMusic == true then
	local folder = script.Parent:FindFirstChild(name1)
		or game.ReplicatedStorage:FindFirstChild(name1)
		or workspace:FindFirstChild(name1)
		or game:FindFirstChild(name1, true)

	if folder then
		for _, v in pairs(folder:GetChildren()) do
			if v:IsA("Sound") then
				v.Parent = global
			end
		end
	else
		error(
			"Cindering's BGM error: Your global background music folder could not be found! You may have deleted/renamed the original folder. It should be named: "
				.. name1
		)
		return
	end
end

if settings.UseGlobalBackgroundMusic == true and #global:GetChildren() == 0 then
	warn(
		"Cindering's BGM warning: Your global background music folder is completely empty; no music will be played from there."
	)
end
if settings.UseMusicZones == true and #zones:GetChildren() == 0 then
	warn(
		"Cindering's BGM warning: Your background music zones folder is completely empty; no music will be played from there."
	)
end

music.Name = "MusicFolder"
music.Parent = container

local count = 0
function recurse(instance)
	for _, v in pairs(instance:GetChildren()) do
		count = count + 1
		recurse(v)
	end
end
recurse(music)
local val = Instance.new("IntValue", container)
val.Name = "ObjectCount"
val.Value = count

container.Parent = game.ReplicatedStorage

script.Parent:Destroy()
