How to make 2 or more sounds play on loop when you step on a button?

  1. What do you want to achieve? 2 or more sounds play on loop when you step on a button
  2. What is the issue? Cannot find anything on this topic since its kinda specific and im new to coding and so therefore i dont really know much
  3. What solutions have you tried so far? Youtube, Defourm, looked on both
1 Like
local Part = script.Parent
local sounds = {Part.Sound1,Part.Sound2}

Part.Touched:Connect(function(Obj)
    if not Obj.Parent:FindFirstChild("Humanoid") then return end
    for _,sound in pairs(sounds) do
       if sound.Looped then return end
       sound.Looped = true
       sound:Play()
    end
end)
1 Like

First of all, put the sounds into the button. I will assume you know how to add sounds and choose the sound, if not then I can help as well. Then rename them to something of your choice…
Create a script and put it inside the button part. Then copy the script below in and edit the script at the top with the instructions. All done then! Tell me if something doesn’t work, and I’ll try my best to help.

sound = script.Parent
Sound1 = sound.Sound1 --Change Sound1 to one of the sounds names
Sound2 = sound.Sound2 --Change Sound2 to one of the sounds names
SecondsWaitCooldown = 10 --Set 10 to the amount of seconds till people can activate the button again
--Usually you would want to set the cooldown to the seconds of the longest audio being activated.
debounce = false
local function playsounds(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
	Sound1.Looped = true
	Sound1:Play()

	print("Played sound1")
	Sound2.Looped = true
	Sound2:Play()
		print("Played sound2")
		debounce = true
		task.wait(12)
		debounce = false
	end
end
script.Parent.Touched:Connect(playsounds)
1 Like

Here’s some more information:

Sounds and Music
Sound

Also, the others have scripted sound.Looped = true but there is a Property in sounds themselves (Looped) that you can manually check to true instead of scripting it every time.

Yes that is true, but scripting it is better practice. It’s also less steps for the OP.

Please explain how scripting it is better practice.

If the sound is already loaded in the Part, and Looped = true, then it doesn’t have to take up space in the script and the microsecond it takes to make it true every time the script runs.

Kinda like if you clone a Part into the workspace and then have to change all its Properties in a script. It’s better to do it one time manually in the original so the item only needs to be cloned with everything already set up.

I see your point, I don’t really know why I didn’t put the sound loop = true property out of the loop or just tell them to do it manually. I’m still a fairly new scripter. I personally think it’s a good practice for the OP since they said they don’t know much about scripting, so this teaches them a bit about object-oriented scripting,(I’m not sure if thats the right term, but you know what I mean) even if they just copy and paste it, they still read it and it’s easy to understand so they will be able to take in that knowledge.

Is it possible i can have multiple parts and if one part is stepped on it removes sound from others basiclly mute/ stops them?

Yes you just do Sound:Stop() or Sound:Pause() on all the sound instances.

Sure, how many sounds/parts do you want, and how many sounds per button/part?

ps: I’ved updated the original script with some improvements including checking if it’s a player or NPC and a cooldown.

i want 4 different buttons for changing sound theres 4 levels in my game

Okay, how many sounds per button though?

2 sounds per each of the buttons

Okay. I’ll work on it right now.

Try this, tell me if it doesn’t work but if I’m correct it should. Also, instead of putting the sounds in the button, just put it into the workspace. Make sure to adjust in the code which ones to play and stop. All you have to do is edit the sound(number) for example Sound1 to play another sound of your choice, make sure to also remove the stops on the sounds you don’t want to be stopped. If you need any more help just ask me.

sound = game.Workspace 
Sound1 = sound.Sound1 -- Set every sound to whatever you named each sound.
Sound2 = sound.Sound2
Sound3 = sound.Sound3
Sound4 = sound.Sound4
Sound5 = sound.Sound5
Sound6 = sound.Sound6
Sound7 = sound.Sound7
Sound8 = sound.Sound8
SecondsWaitCooldown = 10 --Set 10 to the amount of seconds till people can activate the button again
--Usually you would want to set the cooldown to the seconds of the longest audio being activated.
debounce = false
local function playsounds(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
                   sound.Sound1:Stop()
                 sound.Sound2:Stop()
		sound.Sound3:Stop()
		sound.Sound4:Stop()
		sound.Sound5:Stop()
		sound.Sound6:Stop()
		sound.Sound7:Stop()
		sound.Sound8:Stop()
		Sound1.Looped = true
		Sound1:Play()
		print("Played sound1")
		Sound2.Looped = true
		Sound2:Play()
		print("Played sound2")
		debounce = true
		task.wait(12)
		debounce = false
	end
end
script.Parent.Touched:Connect(playsounds)

i will try this in the morning i am gonna sleep (its 2 am where i live)