Hey guys, my script is supposed to subtract the position until it gets to a certain position. It's all working fine, except the door does not stop at the exact point I want it to. Can anyone see what I did wrong?
Sensor1 = script.Parent.Sensors.Sensor1
Sensor2 = script.Parent.Sensors.Sensor2
Door1 = script.Parent.Doors.Door1
Door2 = script.Parent.Doors.Door2
debounce = false
function OpenDoor()
repeat
Door1.CFrame = Door1.CFrame - Vector3.new(0, 0, .1)
wait(.01)
until Door1.Position == Vector3.new(94.2, 18.2, 79.3)
end
Sensor2.Touched:connect(function (hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
if not debounce then
debounce = true
OpenDoor()
debounce = false
end
end)

2 comments
My guess is that there is a floating point error (basically a binary math error, same reason as we can't write (1/3) down as a number - binary has problems with 0.1 if I'm right!). This means that it will never get exactly that position.
Try "until (Door1.Position - Vector3.new(94.2,18.2,79.3)).magnitude < 0.05"