1

# Temporarily disable click detection?

Edited 3 months 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)


0
Edited 8 months 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 23 — 8mo
0

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

0
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)