Hello! So I am currently trying to make a tool that breaks boxes, similar to a crowbar, and everything works, but on my box script the sound plays twice when it’s hit. I’m guessing I might need a debounce, but I’m just not sure how to implement it.
Here is my code:
local Box = script.Parent
local Sound = Box:WaitForChild("Sound")
Box.Touched:Connect(function(hit)
if hit.ClassName == "Part" and hit.Name == "Handle" then
Box.Transparency = 1
Box.CanCollide = false
Sound:Play()
task.wait(4)
Box.Transparency = 0
Box.CanCollide = true
end
end)
local Box = script.Parent
local Sound = Box:WaitForChild("Sound")
local Debounce
Box.Touched:Connect(function(Hit)
if Hit:IsA("BasePart") and Hit.Name == "Handle" then
if Debounce then return end
Debounce = true
local PrevTransparency = Box.Transparency
local PrevCanCollide = Box.CanCollide
Box.Transparency = 1
Box.CanCollide = false
Sound:Play()
task.wait(4)
Box.Transparency = PrevTransparency
Box.CanCollide = PrevCanCollide
Debounce = nil
end
end)
local Box = script.Parent
local Sound = Box:WaitForChild("Sound")
local db = true
Box.Touched:Connect(function(hit)
if hit.ClassName == "Part" and hit.Name == "Handle" then
if db then db = false
Box.Transparency = 1
Box.CanCollide = false
Sound:Play()
task.wait(4)
Box.Transparency = 0
Box.CanCollide = true
task.wait(1) -- maybe
db = true
end
end
end)