Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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

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? ultimate055 150 — 10y
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. Shawnyg 4330 — 10y
0
Yeah I like it, but can you go further into what this "autodoor.sensor" is? PhantomGengar123 0 — 7y
Ad
Log in to vote
-1
Answered by
faruque 30
10 years ago

Here a Model I made hope it is what your looking for: http://www.roblox.com/Sensor-Door-item?id=166724173

Answer this question