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

Stop a sound then play one?

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

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)

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