Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to stop all music on Death?

Currently, I have a sound system in my game. However, since I have multiple songs for multiple areas and people will always spawn in one certain area, I have to put a line to stop every song so that two songs don't play at the same time.

Currently, my music script works like this:

function onTouched(hit)
	script.Parent.Parent.PalaceM:stop()
script.Parent.Parent.CastleM:stop()
script.Parent.Parent.InnM:stop()
script.Parent.Parent.GrassM:stop()
 script.Parent.Parent.CastleM:play()
end
script.Parent.Touched:connect(onTouched)

Is there any way I could simply make any music end upon death?

4 comments

0

is this a localscript?

0

No

0

edited the script. it works for me. and i added debounce because everytime i touched the brick, it kept making the sound, but i was testing it with a short 1 second audio. so this might not affect you as much

1 answer

btw easier way to stop all sounds i typed this here, so if doesnt work, tell me

local playing = false
function onTouched(hit)
for i,v in pairs(script.Parent.Parent:GetChildren()) do
if v:IsA("Sound") then
v:stop()
	if playing == false then
		playing = true
if v.Name == "Sound" then	
v:play()
end
end
end
end
end
playing = false


script.Parent.Touched:connect(onTouched)

3 comments

0

It doesn't do anything besides play the Castle Music without having to go through a part.

0

thats weird

0

It doesn't work because the sounds aren't called "Sound". The names are CastleM, InnM, GrassM, and CastleM. The names of the Sound object must be named Sound for this script to work.

This discussion is preserved as it was. New answers, comments, and votes are closed.