How to have elevator teleport everyone in the elevator

  • This code does not check if a player has left the area!
    use table.remove(elevatorplayers, player) to remove someone from the table
local elevatorplayers = {}

local invispart = elevator.part -- just make it ur part

invispart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then -- checking if it hit a player
table.insert(elevatorplayers, hit.Parent.HumanoidRootPart) -- inserting players humanoidrootpart into table 'elevatorplayers'
end
end)

Door1.Button2.ClickDetector.MouseClick:connect(function()
  for i,v in pairs(elevatorplayers:GetChildren() do -- for i,v loop to teleport every humanoidrootpart in the table
     v.CFrame = -- tp them where you want
    table.remove(elevatorplayers, v) -- removing them from the table once they've been teleported
  end
end)

I would recommend using ZonesPlus to check if someone is in an area, if you dont want to have a big “LEAVE” button when you enter the elevator because its difficult to use ‘.Touched’ to see if a player leaves

2 Likes