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)
You just made this overly complex. You have two functions and two connections, so both functions will run each time you click the button. This makes the variable not work as intended. You just need to combine the functions.
function clickity(playerWhoClicked) 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) end else --meaning, if the switch doesn't equal false Switch = false print('False') for i = 1, 10 do Workspace.Door.CFrame = Workspace.Door.CFrame + Vector3.new(0, -1.2, 0) end end end