When player touch the indicated part doesn't stop the music

Hi everyone!, i. made a part when player touch it a sound is stopped and the other is playing, here is the script:

local sound = game.Workspace.Sound

local lorieBathroom = script.Parent

local silence = game.Workspace.silence

local ToiletSound = game.Workspace.ToiletSound

script.Parent.Touched:Connect(function()

sonido:Stop()

end)

script.Parent.Touched:Connect(function()

silence:Play()

end)

script.Parent.Touched:Connect(function()

ToiletSound:Play()

wait(3)

ToiletSound:Stop()

end)

1 Like

Where was sonido referenced I do not see you referencing it

1 Like

It is the sonido:Stop() and
local sound = game.Workspace.Sound

Oops, I copy the wrong script

local sonido = game.Workspace.Sound
local lorieBathroom = script.Parent
local silence = game.Workspace.silence
local ToiletSound = game.Workspace.ToiletSound

script.Parent.Touched:Connect(function()
	sonido:Stop()
end)

script.Parent.Touched:Connect(function()
	silence:Play()
end)

script.Parent.Touched:Connect(function()
	ToiletSound:Play()
	wait(3)
	ToiletSound:Stop()
end)

Are you sure that the Sound’s ID are valid? (Or did you atleast inserted them) Also, Maybe try changing this code to the one below and let me know if it works.

local sonido = game.Workspace.Sound
local lorieBathroom = script.Parent
local silence = game.Workspace.silence
local ToiletSound = game.Workspace.ToiletSound
local Debounce = false

script.Parent.Touched:Connect(function()
	if Debounce == false then
		Debounce = true

		if sonido.IsPlaying then
			sonido:Stop()
		end

		if not silence.IsPlaying then
			silence:Play()
		end

		ToiletSound:Play()
		task.wait(3)
		ToiletSound:Stop()
		Debounce = false
	end
end)
1 Like

yes, it is valid, it doesn’t have any problem with the new add-on, okay I will test it

no it doesn’t work, it still playing with other sound

Is the Sound looping? Also, Does any other script plays the audio? Make sure you also have the CanTouch Property enabled on the Part. (It must be a BasePart)

yes it is looping, that’s the only part where i’m having troubles, all the others. works perfectly, and the can touch is enabled, (it has a check), what do you mean. with BasePart?

BasePart is anything that is a Part. (Part, MeshPart, TrussPart, WedgePart, etc) Also, If the sound is looping, Maybe you could try disabling the “Looping” property and test it again? If it doesn’t works, Mind you sending the Picture of your Explorer so i can look further into it?

Oh ok!, okay i will try to disable the looping property, and let you know if it works

no, it doesn’t work, isn’t it a problem of Roblox?, before it works perfectly

The solution: `

script.Parent.Touched:Connect(function()
sonido:Play()
wait(1)
silence:Play()
sonido:Stop()