-- This script gets placed into StarterPlayerScripts where it will locally play the background music for each player.


local plr = game.Players.LocalPlayer
local char
local torso

local container = game.ReplicatedStorage:WaitForChild("CinderingBGM")
local settings = require(container:WaitForChild("Settings"))
local musicfolder = container:WaitForChild("MusicFolder")
local globalfolder = musicfolder:WaitForChild("GlobalMusic")
local zonesfolder = musicfolder:WaitForChild("MusicZones")
local servercount = container:WaitForChild("ObjectCount").Value

function GetMatchingCount() --objects can take some time to actually replicate to the client. make sure that the client sees the correct # of objects in the music folder before initializing the rest of the script
	local count = 0
	local function recurse(instance)
		for _,v in pairs(instance:GetChildren()) do
			count = count + 1
			recurse(v)
		end
	end
	recurse(musicfolder)
	if count == servercount then return true end
end

while not GetMatchingCount() do
	wait(.5)
end


function IsCleanRotation(v3values) --check to see whether the rotation is at clean 90 degree increments so we can use the more simplistic calculations for it
	for _,v in pairs(v3values) do
		if not (v%90 <= 0.01 or v%90 >= 89.99) then --why not just check for (v%90 == 0)? because rotations can suffer from floating point inaccuracies
			return false
		end
	end
	return true
end

