Hello, I'm having a problem where I'm making a glass door. I want it to open when clicked, then it closes on the second click. I already have a ClickDetector.
Yeah, it detects it as opened so it closes. It also detects it as closed so it opens.
However, the detection is happening all too fast that it opens and closes, all at the same time.
"wait" won't work. If I make it wait, then it just closes again after a while on its own.
-- Scripted by Glinary
-- left and right glass of Cabinet 1 open and close
--object variables
local Left = script.Parent.Left
-- checks if it's closed
local LeftCloseCheck = {Left.CFrame == CFrame.new(-193.67, 5.72, -7.2), Left.Rotation == Vector3.new(0,0,0)}
-- CFrames and Rotations for closed and opened situations
local LeftOpenCFrame = CFrame.new(-194.88, 5.83, -5.82)
local LeftOpenRotation = Vector3.new(0, -90, 0)
local LeftCloseCFrame = CFrame.new(-193.67, 5.72, -7.2)
local LeftCloseRotation = Vector3.new(0,0,0)
-- checks if it's opened
local LeftOpenCheck = {Left == LeftOpenCFrame, Left == LeftOpenRotation}
-- when object is clicked
Left.ClickDetector.MouseClick:connect(function(player)
--if its closed then it opens
if LeftCloseCheck then
print "im closed so let's open"
Left.CanCollide = false
Left.CFrame = LeftOpenCFrame
Left.Rotation = LeftOpenRotation
end
-- if its opened then it closes
if LeftOpenCheck then
print "i'm opened so let's close"
Left.CFrame = LeftCloseCFrame
Left.Rotation = LeftCloseRotation
end
end)
This is the output after ONE click on the brick.
im closed so let's open
i'm opened so let's close
Thanks for your help and taking the time to read :)

2 comments
You posted the exact same code I posted. Typo? Thanks though. I completely forgot about the "elseif" I'll try to fix it with that and see if it works
Opps