# Accessing motor object of a surface motor

I would like to make a door closer for a door. The door should open normally, but when the person passes through close slowly. I've made an standard door on hinges, but then made one of them a motor and thought to control it when the person passes the door. However, I can't find the motor object on that part which owns the motor-surface. How can I do this properly?

A surface motor is undesirable in this case. Unless you want to dig through JointsService to find the actual instance of the motor, the only control you have over that instance is through the corresponding ParamB property of the part the motor is adorned to. This only gives you control over the rotational speed of the motor, it does not allow you to set a desired angle.

I instead recommend keeping the door on hinges but using a BodyGyro to close it. In this case, simply insert a BodyGyro into the part you are using for your door and set the cframe of the BodyGyro to that of the door part. When you want a player to open the door, simply lower or remove the torque of the BodyGyro. When you want to close the door, increase the torque.

local door = script.Parent
local bodyGyro = Instance.new("BodyGyro", door)
bodyGyro.cframe = door.CFrame

local closingTorque = 10 * door:GetMass()

local function OnTouched(otherPart)
if game.Players:GetPlayerFromCharacter(otherPart.Parent) then
bodyGyro.maxTorque = Vector3.new(0, 0, 0)
wait(2)
bodyGyro.maxTorque = Vector3.new(0, closingTorque, 0)
end
end

door.Touched:connect(OnTouched)


You will have to fiddle with closingTorque to get the behavior you want. Note that it is useful to scale this by the mass of the object to account for doors made with different materials. You could do the math to calculate the exact torque you need to close the door in an exact amount of time, but usually a ballpark will do.