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

Temporarily disable click detection?

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

✓ Accepted answer

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)

1 comment

0

Okay, thanks

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

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