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

I am having trouble with the debounce function in this script?

I don't know if I messed something up, but it does not work at all. Can someone help me debug it? (It uses a click detector)

local debounce = false

function onClicked()
	
local s = Instance.new("Sound")

s.Name = "Sound"
s.SoundId = "http://www.roblox.com/asset/?id=131558930"
s.Volume = 0.5
s.Looped = false
s.archivable = false

s.Parent = game.Workspace
local debounce = true
s:play()
wait(2.5)
local debounce = false
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)  

2 comments

0

Can you fix it so it's neater?

0

Why are u inserting it? Just place it already? And play it?

1 answer

✓ Accepted answer

###The problem is that on lines 14 and 17, you're creating a new debounce, not reassigning the first debounce.

local debounce = false

function onClicked()
    if not debounce then 
           local s = Instance.new("Sound")
	
	    s.SoundId = "rbxassetid://131558930" -- SoundId's use this link format
	    s.Volume = 0.5
	    s.Looped = false
	    s.Archivable = false -- archivable is deprecated, switch to Archivable  
	    s.Parent = game.Workspace

	    debounce = true -- don't add the local 
	    s:Play() -- :play is deprecated, switch to :Play
	    wait(2.5)
	    debounce = false
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)  

###There is some deprecated code, which should not be used in new work. This isn't the problem, but it's good practice to deviate from deprecated code.

3 comments

0

Oh I'm sorry, maybe I didn't describe it enough. You see, I'm creating a doorbell, and when I repeatedly click the doorbell, it repeats the sound and gets annoying. How do I stop this because that script isn't working.

0

I'll edit it.

0

It works, thanks!

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