I've been working on an automatic door and I cannot get this right. When all the players in the server get near the door, the door opens otherwise if only 1 player gets near the door it just shuts and closes over and over. It has something to do with this part:
players = game.Players:children() for i = 1,#players do if (players[i].Character.Torso.Position - sensor.Position).magnitude <= dist
Full script: (Unnecessary parts removed)
sensor = workspace.autodoor.sensor while true do wait(0.1) dist = 25 players = game.Players:children() for i = 1,#players do if (players[i].Character.Torso.Position - sensor.Position).magnitude <= dist and script.Parent.Open.Value == false then script.Parent.Open.Value = true --[[ Stuff that makes the door open]] elseif players[i].Character.Torso.Position - sensor.Position).magnitude >= dist and script.Parent.Open.Value == true then script.Parent.Open.Value = false --[[ Stuff that makes the door close]] end end end
With the first script, you're using a for loop. There's no need to do this. I recommend making this a LocalScript in Workspace and changing your paths so they match up again. Within the local script, you would have a while loop with a wait (So it doesn't crash) that checks if they are near the door. (It could just be wait()).
Here a Model I made hope it is what your looking for: http://www.roblox.com/Sensor-Door-item?id=166724173