I've been trying to fix this code but I can't, what I'm trying to do is when a button is clicked on, the door will close and if that same button is clicked on again it will close. However, every time I try to close it the script will open the door and close it at the same time, so it will just stay in place. Here's my script.
Switch = false
function clockity(dudeWhoClicked)
if Switch == false then
Switch = true
print('True')
for i = 1, 10 do
Workspace.Door.CFrame = Workspace.Door.CFrame + Vector3.new(0, 1.2, 0)--closes the door
end
end
end
function clickity(playerWhoClicked)
if Switch == true then
Switch = false
print('False')
for i = 1, 10 do
Workspace.Door.CFrame = Workspace.Door.CFrame + Vector3.new(0, -1.2 ,0) --opens the door
end
end
end
script.Parent.ClickDetector.MouseClick:connect(clockity)
script.Parent.ClickDetector.MouseClick:connect(clickity)
