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
http://wiki.roblox.com/index.php?title=API:Class/Sound/PlayOnRemove this should help