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

Temporarily disable click detection?

Asked by 3 years ago
Edited 3 years ago

So, I have a script that'll play a sound and popup a dialogue gui on click, and it disappears after 3 seconds. But, sometimes people will spam click the area and the sound spams. How do you temporarily disable the click detector for 8 seconds after it is clicked and then it re-enables. This is what I have

Brick = script.Parent
Sound = Brick.Sound

function onClicked()
wait(1.5)
Sound:Play()
wait(1.5)
Sound:Stop()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

3 answers

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

Heya! Here is a quick edit I made to the script!

Brick = script.Parent
Sound = Brick.Sound
debounce = false -- a var for making cooldowns ect.

function onClicked()
if debounce == false then -- checks if the cooldown is not on
    debounce = true -- cooldown is on, can no longer click the button
    wait(1.5)
    Sound:Play()
    wait(1.5)
    Sound:Stop()
    wait(8)
    debounce = false -- ends the cooldown, can click the button again!
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Okay, thanks alialan626 25 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

set the max click distance to 0 to disable clickdetector and set the max click distance to whatever you had it to before 0

local cd = script.Parent.ClickDetector

cd.MouseClick:Connect(function()
cd.MaxActivationDistance = 0 
wait(1.5)
cd.MaxActivationDistance = 32
Log in to vote
0
Answered by 3 years ago
local Brick = script.Parent
local Sound = Brick.Sound
local cooldown = false

script.Parent.ClickDetector.MouseClick:Connect(function(OnMouseClick)
    if not cooldown then
        cooldown = true
        wait(1.5)
        Sound:Play()
        wait(1.5)
        Sound:Stop()
        wait(8)
        cooldown = false
    end
end)

Answer this question