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

3 comments
Still, it requires all the players to get near the door.. Check line 12, if a player out of all the players isn't near the door it closes. I don't want that, how can I fix it?
Well, that script(with my edits) is saying that it'll close if any single person is far enough. I recommend just adding a wait time and closing it within the script. If you try to detect how far they get, then it'll fail. If you want to try a different way, you can basically have 2 pressure plates (could be invisible) and once someone touches it, it does the opposite function than what it is.
Yeah I like it, but can you go further into what this "autodoor.sensor" is?