local A={}local p=game:GetService("\067\111\110\116\101\110\116\080\114\111\118\105\100\101\114")A.preloadAudio=function(A)local f={}for A,p in pairs(A)do local R=Instance.new("\083\111\117\110\100")R.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..p R.Name=A R.Parent=game.Workspace table.insert(f,R)end local R,u=pcall(function()p:PreloadAsync(f)end)end local f A.playBackgroundAudio=function(A)if f then f:Stop()end f=game.Workspace:FindFirstChild(A)if not f then warn("\067\111\117\108\100 \110\111\116 \102\105\110\100 \097\117\100\105\111 \097\115\115\101\116\058 "..A)return end if not f.IsLoaded then f.Loaded:wait()end f.Looped=true f:Play()end A.playAudio=function(A,p)local f=game.Workspace:FindFirstChild(A)if not f then warn("\067\111\117\108\100 \110\111\116 \102\105\110\100 \097\117\100\105\111 \097\115\115\101\116\058 "..A)return end if p then local R=p:FindFirstChild(A)if not R then R=f:Clone()R.Parent=p R.EmitterSize=10 R.MaxDistance=100 end f=R end f:Play()end return A
local AudioPlayer = {}

-- Roblox services
local ContentProvider = game:GetService('ContentProvider')

-- Function to preload audio assets
AudioPlayer.preloadAudio = function(assetArray)
	local audioAssets = {}

	-- Add new "Sound" assets to "audioAssets" array
	for name, audioID in pairs(assetArray) do
		local audioInstance = Instance.new('Sound')
		audioInstance.SoundId = 'rbxassetid://' .. audioID
		audioInstance.Name = name
		audioInstance.Parent = game.Workspace
		table.insert(audioAssets, audioInstance)
	end

	local success, assets = pcall(function()
		ContentProvider:PreloadAsync(audioAssets)
	end)
end

local currentBackground
-- Function to play an audio asset
AudioPlayer.playBackgroundAudio = function(assetName)
	if currentBackground then
		currentBackground:Stop()
	end

	currentBackground = game.Workspace:FindFirstChild(assetName)
	if not currentBackground then
		warn('Could not find audio asset: ' .. assetName)
		return
	end
	if not currentBackground.IsLoaded then
		currentBackground.Loaded:wait()
	end

	currentBackground.Looped = true
	currentBackground:Play()
end

AudioPlayer.playAudio = function(assetName, part)
	local audio = game.Workspace:FindFirstChild(assetName)

	if not audio then
		warn('Could not find audio asset: ' .. assetName)
		return
	end

	if part then
		local partAudio = part:FindFirstChild(assetName)
		if not partAudio then
			-- clone so we can use cached sound in other parts also
			partAudio = audio:Clone()
			partAudio.Parent = part
			partAudio.EmitterSize = 10
			partAudio.MaxDistance = 100
		end
		audio = partAudio
	end

	audio:Play()
end

return AudioPlayer