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

How do I make this work for multiple people?

Asked by
PWNTART 33
9 years ago

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

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

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)

0
You may need to check line 11. Redbullusa 1580 — 9y
0
Yup. I'd just do game.Players:GetPlayerFromCharacter(script.Parent) or leave.Parent:FindFirstChild("Humanoid") funyun 958 — 9y
0
oh..never thought about that 0-0 PWNTART 33 — 9y
0
Doesnt completely fix it but its much better PWNTART 33 — 9y
0
Yeah, I wasn't looking at that. I'll do that. Shawnyg 4330 — 9y
Ad

Answer this question