ContentProvider:PreloadAsync(workspace.Scripts.MainModule:GetDescendants())function SetSounds(L)ContentProvider:PreloadAsync(workspace.Scripts.MainModule:GetDescendants())LocalSounds=L end function PlayNoteSound(L,w,F,K,z,b)local A=1 if L>61 then A=1.059463^(L-61)elseif L<1 then A=1.059463^(-(1-L))end L=L>61 and 61 or L<1 and 1 or L local B=(L-1)%12+1 local m=math.ceil(L/12)local q=16*(m-1)+8*(1-B%2)local Y=math.ceil(B/2)local E=Instance.new("\083\111\117\110\100",SoundFolder)E.SoundId="\104\116\116\112\115\058\047\047\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061"..(K and K[Y]or LocalSounds[Y])if w then local L=1/F^2 local K=(game.Workspace.CurrentCamera.CoordinateFrame.p-w).magnitude local b=-L*K^2+1 if b<.01 then E:remove()return end E.Volume=b*z else E.Volume=Volume end if fade then delay(.75,function()for L=1,5,1 do E.Volume=E.Volume*.75 wait(.1)end E:Stop()E:Destroy()end)end E.TimePosition=q+((b or specialPiano)and.04 or(m-.9)/15)E.Pitch=A E:Play()table.insert(ExistingSounds,1,E)if#ExistingSounds>=15 then ExistingSounds[15]:Stop()ExistingSounds[15]=nil end delay(5,function()E:Stop()E:remove()end)end

ContentProvider:PreloadAsync(workspace.Scripts.MainModule:GetDescendants())
function SetSounds(sounds)
	ContentProvider:PreloadAsync(workspace.Scripts.MainModule:GetDescendants())
	LocalSounds = sounds
end

function PlayNoteSound(note, source, range, sounds, vol, SpecialPiano)	

	local pitch = 1
	if note > 61 then
		pitch = 1.059463 ^ (note - 61)
	elseif note < 1 then
		pitch = 1.059463 ^ (-(1 - note))
	end
	note = note > 61 and 61 or note < 1 and 1 or note
	local note2 = (note - 1)%12 + 1	-- Which note? (1-12)
	local octave = math.ceil(note/12) -- Which octave?
	local offset = (16 * (octave - 1) + 8 * (1 - note2%2))
	local sound = math.ceil(note2/2) -- Which audio?
	
	local audio = Instance.new("Sound", SoundFolder) -- Create the audio
	audio.SoundId = "https://roblox.com/asset/?id="..((sounds and sounds[sound]) or LocalSounds[sound]) -- Give its sound
	
	if source then
		local a = 1/range^2
		local distance = (game.Workspace.CurrentCamera.CoordinateFrame.p - source).magnitude
		local volume = -a*distance^2 + 1
		if volume < 0.01 then
			audio:remove()
			return
		end
		audio.Volume = volume * vol
	else
		audio.Volume = Volume;
	end
	if fade then
		delay(0.75, function()
			for i = 1, 5 do
				audio.Volume = audio.Volume * 0.75
				wait(0.1)
			end
			audio:Stop()
			audio:Destroy()
		end)
	end
	audio.TimePosition = offset + ((SpecialPiano or specialPiano) and 0.04 or (octave - .9)/15) -- set the time position
	audio.Pitch = pitch
	audio:Play() -- Play the audio
	
	table.insert(ExistingSounds, 1, audio)
	
	if #ExistingSounds >= 15 then
		ExistingSounds[15]:Stop() -- limit the number of playing sounds!
		ExistingSounds[15] = nil
	end
	delay(5, function() audio:Stop() audio:remove() end ) -- remove the audio in 4 seconds, enough time for it to play
end
