Background:
I am trying to make an automatic door for a game in Roblox, and I am having some script errors. This door is a proximity sensor door that uses an invisible brick to sense when you get close (i couldn't make it work any other way). Here is my script:
local X = script.parent.moveReference.position.X
local Y = script.parent.moveReference.position.Y
local Z = script.parent.moveReference.position.Z
local Part = workspace.Door.door and workspace.Door.window -- Part we will move
local newPos = Part.Position + Vector3.new(X, Y, Z) -- Position Part will go to
local Time = 0.6 -- the time that the script will take to move the part
local Increment = 0.3 -- the part will move 0.5 studs each time it moves
local Debounce = false
local Diff = newPos - Part.Position -- The difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, newPos).lookVector
warn("Vars Defined Succesfilly!")
function MovePart() -- function to move the part
warn("Ran Function!")
if Debounce == true then return end -- end the function if debounce is true
Debounce = true -- Make debounce true so the function can't run
for n = 0, Mag, Increment do
warn("For loop ran!")
Part.CFrame = (Direction * Increment)
wait( (Time/Mag) *Increment)
end
Debounce = false -- Set debounce to false so the function can't run again
end
workspace.Door.sensor.Touched:Connect(MovePart)
warn("Loops Over!")
Problem:
The Lua Debugger shows no issues with the code, and the output shows no errors, but the door does not move when I'm in range of the door. If you have a possible solution to this issue, please help.

4 comments
I'd suggest making the script print something in the for loop to see if the script reaches that far before failing.
:OnTouched?
yeah what is ontouched i wonder hmmm maybe roblox added that recently just use .Touched
yeah what is ontouched i wonder hmmm maybe roblox added that recently just use .Touched