Button cooldown not working

I have a box that rotates when a button is clicked, I have 2 buttons, one on the ceiling and the other on the floor. Although the rotating works fine I noticed you can click on the other button and it could mess up the rotation. I inserted a boolean value and made this script but it doesn’t work, it did detect that it was false and I even did some debugging and it does change it to true but it does not do what I tell it to do.

	if BoxDeb == false then
		BoxDeb = true	
		print("rotating")	
		rotation:Play()
		wait(2.5)
		BoxDeb = false
		print("done")
	end
end)

if BoxDeb == true then
	script.Parent:Destroy()
	B.Brickcolor = BrickColor.new("Bright green")
end

if BoxDeb == false then
	local ClickDetector = Instance.new("ClickDetector")
	ClickDetector.Parent = B
	ClickDetector.MaxActivationDistance = 5
	B.BrickColor = BrickColor.new("Brick yellow")
end
local BoxDeb = false
local ClickDetector -- = Click detector here

ClickDetector.MouseButton1Down:Connect(function()
if BoxDeb == true then return end
if BoxDeb == false then
-- rotate the part
BoxDeb = true
spawn(function()
wait(2.5)
BoxDeb = false
end)
end
end)

This should be cleaner and should solve your issue here.

I’m curious, what is the 2nd function for?

It’s for the cooldown, you can remove there’s no use for it. Here’s the script:

local BoxDeb = false
local ClickDetector -- = Click detector here

ClickDetector.MouseButton1Down:Connect(function()
if BoxDeb == true then return end
if BoxDeb == false then
-- rotate the part
BoxDeb = true
wait(2.5)
BoxDeb = false
end
end)

Mh, not seeing any changes.

30char