How would I be able to check for 2 player before doing a function

Hello! I am WEcompany who is working on my next game. What I want to know is how would I be able to Wait for 2 different object values before doing these specific function

local Car = script.Parent
wait(25)
while true do
 wait(30) 
 for i = 1,930 do
  Car:TranslateBy(Vector3.new(0,-0.03,0)) 
  wait()
 end
 for i = 1,930 do
  Car:TranslateBy(Vector3.new(-0,0.03,0)) 
  wait()
 end
end
local door = script.Parent 
wait(25)
while true do

door.Transparency = 1
door.CanCollide = false
wait(30)
door.Transparency = 0
door.CanCollide = true
wait(61.89)
end 

I just want to finish the elevators so we can work on the next thing.
If you can help, please respond. Thanks!
If you need more information, please let me know.

1 Like

If I understood correctly, you might want to use :WaitForChild(), but I’m not sure which objects you are waiting for.

1 Like

you could do

repeat wait(1) until object1 = true and object2 = true

Yeah I Think Your Right Wizard

But what if the object is a players name?

Its a condition wait meaning it could be anything

until plr ~= nil
--or
until player.Name = "BuilderMan"
--or
until workspace.Baseplate.Transparency = 1

--basically an if statement

It is something like this:
image

If you’re waiting for objects with specific players’ names to be inserted, you should use WaitForChild like Dark mentioned.

If you’re waiting for a certain number of player values to exist in that folder, you could use a loop with local num = #TeleportPoint.Players:GetChildren(), or use ChildAdded and keep track of it that way.

Adding onto what @sean21307 said,
If you are awaiting a certain amount of players, you could easily make a repeat wait() until num >= required loop for it, where required would be any amount you desire or see if specified people are listed by making checks inside of the loop and then ending the loop by seeing if the check is true.

Well I don’t get what @sean21307 said. I also don’t know where to put it inside the script.

Generally if objects can come and go, I’d use FindFirstChild(), eg:

while true  do
    local one = foo:FindFirstChild( desiredName1 )
    local two = foo:FindFirstChild( desiredName2 )
    if one and two  then
        if one.Whatever == desired1whatever and two.Whatever == desired2whatever  then
             -- Do whatever here (Both objects and values exist.)
             break
        end
    end
    -- Yield here
end

Well… It is a random user that goes in the elevator. Not a specific user.

If you’re awaiting just a specific or higher number of the players not SPECIFIC players, you can do:

repeat
    wait()
until #TeleportPoint.Players:GetChildren() >= 2

And would #TeleportPoint be this folder?
image
The one labeled Players?

Well then you can use GetChildren() as mentioned earlier and iterate through the children, and if you have two, go from there.
Edit:
I’m assuming you have the ‘elevator’ players in a table, or Values parented to an object already somewhere.
Or are you asking how to initially select two random players?

Yes, TeleportPoint.Players would be the Players folder inside the TeleportPoint part :slight_smile:

But now the doors arent opening.
Here is what im doing:

local door = script.Parent 
local TeleportPoint = script.Parent.Parent.TeleportPoint
wait()

while true do
door.Transparency = 1
door.CanCollide = false
 repeat
    wait()
until #TeleportPoint.Players:GetChildren() >= 2 
door.Transparency = 0
door.CanCollide = true
wait(61.89)
end 
local Car = script.Parent
local TeleportPoint = script.Parent.Parent.TeleportPoint
wait()
while true do
 repeat
    wait()
until #TeleportPoint.Players:GetChildren() >= 2 
 for i = 1,930 do
  Car:TranslateBy(Vector3.new(0,-0.03,0)) 
  wait()
 end
 for i = 1,930 do
  Car:TranslateBy(Vector3.new(-0,0.03,0)) 
  wait()
 end
end

You don’t need to do TeleportPoint.Players if the variable is already that, and I don’t think you meant to have the repeat loop in the while loop.

local door = script.Parent 
local TeleportPoint = script.Parent.Parent.TeleportPoint.Players
wait()

repeat
    wait()
until #TeleportPoint.Players:GetChildren() >= 2 

while true do
	door.Transparency = 1
	door.CanCollide = false
	door.Transparency = 0
	door.CanCollide = true
	wait(61.89)
end 
local Car = script.Parent
local TeleportPoint = script.Parent.Parent.TeleportPoint
wait()

repeat
    wait()
until #TeleportPoint.Players:GetChildren() >= 2 

while true do
 	for i = 1,930 do
  		Car:TranslateBy(Vector3.new(0,-0.03,0)) 
  		wait()
 	end
 	for i = 1,930 do
  		Car:TranslateBy(Vector3.new(-0,0.03,0)) 
  		wait()
 	end
end

The elevators are not working at all. Can you give me the full script? If needed, I can give a model.

It still isn’t working. Is there anyone who can help?