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

How to I get a script to wait until 8 people are in a elevator before it starts? HELP! [closed]

Asked by 5 years ago
Edited 5 years ago

Im trying to get a elevator to start moving when 8 players are in the elevator how would i do this?

0
Place a part inside then use a touched event, use the functions arguments to retrieve the character then store the characters name inside of a table and use an if statement to check if the characters name is not equal to another value inside of the table, check if the tables value by using table.getn is equal to 8 then run the elevator code. Hope this helped! Theswagger66 54 — 5y

Closed as Not Constructive by zblox164, namespace25, Lugical, and Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Cizox 80
5 years ago
Edited 5 years ago

This is one way of doing it. Continuously checks the interior of the elevator using Region3 and FindPartsInRegion3 and checks the amount of players inside the elevator until 8 players are found. Be sure to modify min and max to replicate the actual size and coordinates of your elevator.

This also wasn't tested, so i'm not sure it works, but the algorithm should be correct. Let me know if you have any trouble.

local min = Vector3.new(0, 0, 0)
local max = Vector3.new(10, 10, 10)

local region = Region3.new(min, max)

while true do
    local container = game.Workspace:FindPartsInRegion3(region, 100)
    local players = {}

    for _, child in pairs(container) do
        if (child.Parent:FindFirstChild("Humanoid")) then
            for _, element in pairs(players) do
                if (element.Name == child.Parent.Name) then
                    break
                end
            end

            table.insert(players, child.Parent.Name)
        end
    end

    if (#players >= 8) then
        startGame()
    end

    wait(1)
end
Ad
Log in to vote
-1
Answered by 5 years ago
local touchCount = 8-- Amount of People
local touchers = {" "} --Elevator Part Name
script.Parent.Touched:Connect(function(p)
    if p:IsA("BasePart") then
        touchCount = touchCount + 1
        table.insert(touchers,p.Parent.Name)
    end
end)
local TeleportID = 1 --Place ID
spawn(function()
    while true do wait()
        if touchCount >= 8 then
            for_, Plr in pairs(game.Players:GetChildren()) do
                game:GetService("TeleportService"):Teleport(TeleportID,Plr)
            end
        end
    end
end)
0
Wouldn't work if a player resets or steps on it again. User#25281 0 — 5y
0
Yeah it would... AwesomeMrBird -79 — 5y
0
touchCount was never deducted Goulstem 8144 — 5y