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

How do I make this work for multiple people?

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)

1 answer

✓ Accepted answer

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)

5 comments

0

You may need to check line 11.

0

Yup. I'd just do game.Players:GetPlayerFromCharacter(script.Parent) or leave.Parent:FindFirstChild("Humanoid")

0

oh..never thought about that 0-0

0

Doesnt completely fix it but its much better

0

Yeah, I wasn't looking at that. I'll do that.

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