Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to stop all music on Death?

Asked by 7 years ago

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?

0
is this a localscript? RobloxianDestory 262 — 7y
0
No Crazy_Zilliness -5 — 7y
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 RobloxianDestory 262 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)
0
It doesn't do anything besides play the Castle Music without having to go through a part. Crazy_Zilliness -5 — 7y
0
thats weird RobloxianDestory 262 — 7y
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. MacaylaMarvelous81 15 — 5y
Ad

Answer this question