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

How do I make the sound get deleted after it has played ONCE? [SOLVED]

I want the sound to get destroyed after it has been played once, but I can't really get it to work.

How can I make it so that it gets destroyed after it has been played once?

The Sound Section Starts At Line 35

repeat wait()
	Player = game.Players.LocalPlayer
	Button = script.Parent
	Item = game.ReplicatedStorage:FindFirstChild(script.Parent.Name)
	Cost = script.Parent.Price.Value
	Money = Player.leaderstats.Money
until

Button.MouseButton1Down:connect(function(purchase)
	if Money.Value > (Cost - 1) then
			Money.Value = Money.Value - Cost
			local a = Item:Clone()
			a.Parent = Player.Backpack
			local b = Item:Clone()
			b.Parent = Player.StarterGear
			
			local PurchaseCounter = game.Players:FindFirstChild(Player.Name):FindFirstChild("PurchaseCounterFor"..Player.Name)
			
			local TotalPurchases = script.Parent.Parent.Parent.TotalPurchases			
			
			print(
			
				"Cha-Ching! "..script.Parent.Name.." Was Bought By "..Player.Name.."! "
			
				..script.Parent.Price.Value.."$ Has Been Charged From "..Player.Name..
			
				"'s In-Game Money! Enjoy Your "..script.Parent.Name..", "..Player.Name.."!"
				
				)
		
			PurchaseCounter.Value = PurchaseCounter.Value + 1
			
			TotalPurchases.Text = "Total Purchases: "..PurchaseCounter.Value
			
			local Sound = Instance.new("Sound")                 --The Cha-Ching Sound
			Sound.SoundId = "http://www.roblox.com/asset/?id=131886985"
			Sound.Parent = Player.PlayerGui.SoundFixGui
			
			local SoundToggle = game.Players:FindFirstChild(Player.Name):FindFirstChild("SoundOnOffFor"..Player.Name)			
			
			if SoundToggle.Value then
				Sound:Play()
			else
				Sound:Stop()
			end
			
		end
		
end)

1 comment

1 answer

I managed to make it work by implementing this into the script.

if SoundToggle.Value then
	Sound:Play()
	wait(1)
	Sound:Remove()
else
	Sound:Stop()
	wait(1)
	Sound:Remove()
end

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