Ive been trying to make it so when you click a part it removes click detector then creates it again once the script is over. But I couldent figuare it out how to do it so im asking you.
So heres the script:
door = script.Parent function move() Workspace.Door.ClickDetector:Remove() door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,0.2,0) wait(5) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) end door.ClickDetector.MouseClick:connect(move)
Please use a loop for this, as it is tedious for many people to look through. As far as I can see, there are no errors with part beginning to move. As for putting back the clickdetector, just use the debounce system. See debounce here.
Instead of removing the clickdetector, simply add a variable and set it to true or false. Say you chose false. When the door is opening/closing, set the variable to the true. After it's done, reset the variable(change it back to false) Before the script runs, write an if statement. This if statement should check if your variable is true or false and makes sure that if your variable is false, the script will run, otherwise nothing will happen.
Instead of looping the door's movement 29 times, you can simply use
for i = 1, 29 do door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) end wait(5) for i = 1, 29 do door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) end
Hope this helped :)
local door = script.Parent function move() door.ClickDetector:remove() -- shouldn't be capped for i =1, 30 do i = i+1 door.Position = door.Position + Vector3.new(0,0.2,0) wait(0.1) end wait(5) for i =1, 30 do i = i+1 door.Position = door.Position + Vector3.new(0,-0.2,0) wait(0.1) end end door.ClickDetector.MouseClick:connect(move)
There you go. :D