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


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 - .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
