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

Stop a sound then play one?

Asked by
NotSoNorm 777 Moderation Voter
10 years ago

Im trying to make it so when you click on a SurfaceGui it will play a song. Im having trouble with spamming songs. How would you make it so if there is a song already playing, it will stop it and will play the one you click on?

bin = script.Parent
function Clicked()
    bin.Parent.Sound.Archivable = true
    bin.Parent.Sound.SoundId = "rbxassetid://148492408"
    bin.Parent.Sound:Play()
    bin.Parent.Sound.Archivable = false
end
bin.MouseButton1Down:connect(Clicked)

1 answer

Log in to vote
0
Answered by
Tesouro 407 Moderation Voter
10 years ago

You could use the Stop() method. If all the playing sounds are bin child:

bin = script.Parent
function Clicked()
    for i, child in pairs (bin:GetChildren()) do
        if child:IsA("Sound") then
            child:Stop()
        end
    end
    bin.Parent.Sound.Archivable = true
    bin.Parent.Sound.SoundId = "rbxassetid://148492408"
    bin.Parent.Sound:Play()
    bin.Parent.Sound.Archivable = false
end
bin.MouseButton1Down:connect(Clicked)
Ad

Answer this question