Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this door open when 1 player gets near it instead of all?

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

2 answers

✓ Accepted answer

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()).

3 comments

0

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?

0

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.

0

Yeah I like it, but can you go further into what this "autodoor.sensor" is?

This discussion is preserved as it was. New answers, comments, and votes are closed.