So basically it works but lets say there are 2 ppl in the door scanner and 1 of them exits it. It will close even though there is still a person there. How do i make it so that it doesnt close until there is no one inside the brick.
script.Parent.Touched:connect(function(hit) if hit ~= nil then game.Workspace.Door.BodyPosition.position = script.Parent.AYE.Value end end) script.Parent.TouchEnded:connect(function(leave) if leave.Name == "Head" or "Torso" or "Left Leg" or "Right Leg" or "Left Arm" or "Right Arm" ~= nil then wait(1.5) game.Workspace.Door.BodyPosition.position = script.Parent.BEE.Value end end)
Well, think of it like this. You basically want to keep count of how many people are in the door, correct? So, make a variable called count
, or something else. In your Touched function, after line 3, add count = count + 1
. In your TouchEnded, count = count - 1
Now, here's the part where it checks. In your TouchEnded function, before it closes the door, have it check if count is equal to 0! So, here is your script:
count = 0 script.Parent.Touched:connect(function(hit) if hit ~= nil then game.Workspace.Door.BodyPosition.position = script.Parent.AYE.Value count = count + 1 end end) script.Parent.TouchEnded:connect(function(leave) if leave.Name == "Head" or leave.Name == "Torso" or leave.Name =="Left Leg" or leave.Name =="Right Leg" or leave.Name =="Left Arm" or leave.Name == "Right Arm" then wait(1.5) count = count - 1 if (count == 0) then game.Workspace.Door.BodyPosition.position = script.Parent.BEE.Value end end end)