How do i stop playing a sound when player is seated?

Hi, i recently added pianos in my game Mossy Grove, however the game has music aswell. i want the music to stop playing when the player is seated on the piano bench, when the player gets off it should start playing again. does anyone know how thats posible. theres also a mute music button, it uses volume. can anyone help to find the right solution for me?

Heres the script the music uses.

local SongsList = {"rbxassetid://13750874337", "rbxassetid://13758464835", "rbxassetid://13673577343", "rbxassetid://13750957344", "rbxassetid://13758567291", "rbxassetid://13751296484", "rbxassetid://13751116938", "rbxassetid://13758468499", "rbxassetid://13753573646", "rbxassetid://13757342102", "rbxassetid://13757365808", "rbxassetid://13758492839"}

----------------------------------------------------------------------------------------------
local Sound = workspace:WaitForChild("Sound1")

local function PlaySongs()
	for Index = 1, #SongsList do
		Sound.SoundId = SongsList[Index]
		Sound.TimePosition = 0
		Sound.Volume = 0.5
		Sound:Play()
		wait(Sound.TimeLength)
		if Index == #SongsList then
			PlaySongs()
		end
	end
end

PlaySongs()

You can add a tag (e.g. “Music”) to the sound instance(s) before runtime or when you create it. When the player sits down, you can use CollectionService:GetTagged to get those sounds. Then just loop through them and mute or pause them.

1 Like