function PreloadAudio(l)for l,O in pairs(l)do ContentProvider:Preload("\114\098\120\097\115\115\101\116\105\100\058\047\047"..O)end end function SetSounds(l)PreloadAudio(l)LocalSounds=l end function PlayNoteSound(l,O,h,A)local K=A or LocalSounds local Q=(l-1)%12+1 local f=math.ceil(l/12)local C=math.ceil(Q/2)local V=16*(f-1)+8*(1-Q%2)local H=Instance.new("\083\111\117\110\100",SoundFolder)H.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..K[C]if O then local l=1/h^2 local A=(game.Workspace.CurrentCamera.CoordinateFrame.p-O).magnitude local K=-l*A^2+1 if K<.05 then H:remove()return end H.Volume=K end H.TimePosition=V+(f-.9)/15 H:Play()table.insert(ExistingSounds,1,H)if#ExistingSounds>=10 then ExistingSounds[10]:Stop()ExistingSounds[10]=nil end delay(4,function()H:Stop()H:remove()end)end
----------------------------------
------------FUNCTIONS-------------
----------------------------------

function PreloadAudio(sounds)
	for i, v in pairs(sounds) do
		ContentProvider:Preload("rbxassetid://" .. v)
	end
end
function SetSounds(sounds)
	PreloadAudio(sounds)
	LocalSounds = sounds
end
function PlayNoteSound(note, source, range, sounds)
	local SoundList = sounds or LocalSounds

	local note2 = (note - 1) % 12 + 1 -- Which note? (1-12)

	local octave = math.ceil(note / 12) -- Which octave?

	local sound = math.ceil(note2 / 2) -- Which audio?

	local offset = 16 * (octave - 1) + 8 * (1 - note2 % 2) -- How far in audio?

	local audio = Instance.new("Sound", SoundFolder) -- Create the audio
	audio.SoundId = "rbxassetid://" .. SoundList[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.05 then
			audio:remove()
			return
		end
		audio.Volume = volume
	end
	audio.TimePosition = offset + (octave - 0.9) / 15 -- set the time position
	audio:Play() -- Play the audio

	table.insert(ExistingSounds, 1, audio)
	if #ExistingSounds >= 10 then
		ExistingSounds[10]:Stop() -- limit the number of playing sounds!
		ExistingSounds[10] = nil
	end

	delay(4, function()
		audio:Stop()
		audio:remove()
	end) -- remove the audio in 4 seconds, enough time for it to play
end
