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

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

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

1 comment

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!

2 answers

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

3 comments

0

Wouldn't work if a player resets or steps on it again.

0

Yeah it would...

0

touchCount was never deducted

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