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)
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)