How Do I Make Sound Play Once?

So how would access the sound instead of Instance.new?

Create it in the explorer manually and reference it with a variable

So do you just say local sound = game.Workspace.Part?

Something like that:

local sound = game.Workspace.Part.Sound

Create Sound manually inside Part

Ahhhh, well that works but it still runs it three times :face_with_raised_eyebrow:

Can you show your complete code?

local Sound = game.Workspace.Part.Sound
Sound.Looped = false
local debounce = false

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		Sound:Play()
		task.wait()
		Part.Transparency = 1
		Part.CanCollide = false
		wait()
		Part.GlassShatter.Enabled = true
		Part.GlassShatter.Rate = 100
		Part.GlassShatter.Life = NumberRange.new(1,1) 
		task.wait()
		print("Ran")
		Part.GlassShatter.Enabled = false
		Sound:stop()
		debounce = true        
	end
end)

Try this:

local Sound = game.Workspace.Part.Sound
Sound.Looped = false
local debounce = false

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
        debounce = true     
		Sound:Play()
		task.wait()
		Part.Transparency = 1
		Part.CanCollide = false
		wait()
		Part.GlassShatter.Enabled = true
		Part.GlassShatter.Rate = 100
		Part.GlassShatter.Life = NumberRange.new(1,1) 
		task.wait()
		print("Ran")
		Part.GlassShatter.Enabled = false  
        Sound:Stop()
        Sound:Destroy() 
	end
end)
3 Likes

That fixed it, the debounce needed to be first, thanks for the help! God bless.

3 Likes