:Connect multiple sounds to one function

Is there a way that I could use :Connect to do a function on multiple audios such as in the demonstration below?

sound01.Played or sound02.Played:Connect(function()
	print("a sound has played")
end)

Obviously the code above doesn’t work. But is there a way that it could? Or would I have to copy and paste :Connect(function() for each audio.

function Check()
print("a sound has played")
end
sound01.Played:Connect(Check)
sound02.Played:Connect(Check)
2 Likes

Better than what I was typing at the moment LMAO this is the best way to approach this :smile:

1 Like

Wow never would have thought of that! Need to remember that you can add functions inside brackets. Thank you!!

1 Like
local sounds = {sound1,sound2,sound3}
local function Test()
  print("Works!")
end

for _,Sound in pairs(sounds) do
    Sound.Played:Connect(Test)
end
1 Like

both works, i don’t think he would need alot of sounds to connect in the same function.

Well, I have 9 sounds so this is deff cleaner in the script. And gets rid of the distracting block I had lol

image