It is running the loops successfully but the parts' position in the workspace is not changing.
detector = script.Parent
gate = game.Workspace.Gate
open = false
position = gate.Position.Y
detector.MouseClick:Connect(function()
if open == false then
detector.MaxActivationDistance = 0
for i = 1,17 do
print("moved")
position = position + 1
wait(0.5)
end
detector.MaxActivationDistance = 15
open = true
else
detector.MaxActivationDistance = 0
for i = 1,17 do
position = position - 1
wait(0.5)
end
open = false
detector.MaxActivationDistance = 15
end
end)

3 comments
Im pretty sure if you set open value to true it stops the loop. Im not sure tho
it sets it to true after the function has already ran so that is not the case.
I think it's "Clicked" instead of mouse click.