I have this gate that slides to open and close. There's a button with a ClickDetector to open and close the gate. Now I got the buttons to work, but there's a slight problem. If you spam click either button, the gate will slide further than intended to and will ultimately leave its frame. Here's the script within the open button.
script.Parent.ClickDetector.MouseClick:connect(function()
local Gate=game.Workspace.gate.GateDoor.Gate
local Clicked = false
if Clicked==false then
Clicked =true
print("debounce true")
for i=1,Gate.Size.y*5+1 do
Gate.CFrame=Gate.CFrame*CFrame.new(0,-0.2,0)
wait()
end
wait()
Clicked=false
print("debounce false")
end
end)
clicking a lot will have it print "debounce true" many times and then "debounce false" for just as many times. How do I make it so that you cannot click this button more than once in a row and you can't click it while the loop is running? Thank you.

1 comment
Thanks, but now I have to figure out how to prevent someone from clicking both buttons at the same time and having someone click the same button twice