Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Roblox Remove and Create ClickDectector problem?

Asked by 10 years ago

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)

2 answers

Log in to vote
2
Answered by 10 years ago

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 :)

0
how do i put click detector to false and to true? LittleBigDeveloper 245 — 10y
0
I don't think that's possible, sorry. xolbStudios 127 — 10y
Ad
Log in to vote
-1
Answered by
lomo0987 250 Moderation Voter
10 years ago
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

0
does capital :Remove() make a difference? o.o xolbStudios 127 — 10y
0
Yes. It makes it so it doesn't work. lomo0987 250 — 10y

Answer this question