Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)  
0
Can you fix it so it's neater? Mr_Unlucky 1085 — 5y
0
Why are u inserting it? Just place it already? And play it? MaxDev_BE 55 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

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. HimoutoUmaruDomaChan 20 — 5y
0
I'll edit it. User#19524 175 — 5y
0
It works, thanks! HimoutoUmaruDomaChan 20 — 5y
Ad

Answer this question