So I'm making an elevator game and I made a lobby so players choose to go into the elevator and not get teleported so I made a table to access all the players detect if they are in the elevator but I wanted to make when they die they get removed from the table so they won't get teleported but my code won't work, can someone help?
Here's my code its at line 55
-- Variables
local elevatorFolder = workspace:WaitForChild("Elevator")
local elevator = workspace:WaitForChild("Elevator"):WaitForChild("Elevator")
local replicatedStorage = game:GetService("ReplicatedStorage")
local floorsFolder = replicatedStorage:WaitForChild("Floors")
local floors = floorsFolder:GetChildren()
local AvailableMusic = workspace:WaitForChild("ElevatorMusic"):GetChildren()
local randomMusic = AvailableMusic[math.random(1,#AvailableMusic)]
open = false
door1 = elevatorFolder:WaitForChild("Door1")
door2 = elevatorFolder:WaitForChild("Door2")
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local Door1Open = {CFrame = door1.CFrame + door1.CFrame.lookVector * 4}
local Door2Open = {CFrame = door2.CFrame + door2.CFrame.lookVector * 4}
local Door1Close = {CFrame = door1.CFrame}
local Door2Close = {CFrame = door2.CFrame}
local Open1 = TweenService:Create(door1,tweenInfo,Door1Open)
local Open2 = TweenService:Create(door2,tweenInfo,Door2Open)
local Close1 = TweenService:Create(door1,tweenInfo,Door1Close)
local Close2 = TweenService:Create(door2,tweenInfo,Door2Close)
local ElevatorPart = workspace:WaitForChild("Lobby"):WaitForChild("TeleportInElevator")
local function openDoors()
if open == false then
Open1:Play()
Open2:Play()
wait(2)
open = true
end
end
local function closeDoors()
if open == true then
Close1:Play()
Close2:Play()
wait(2)
open = false
end
end
local plrs = {}
ElevatorPart.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace:WaitForChild("Lobby"):WaitForChild("TPPart").Position)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
wait(3)
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace:WaitForChild("Elevator"):WaitForChild("TPPart").Position)
if player then
table.insert(plrs,player)
elseif player.Character.Humanoid.Died then
table.remove(plrs,player)
end
end
end)
while true do
randomMusic:Play()
wait(14)
randomMusic:Stop()
local randomFloor = floors[math.random(1,#floors)]
local clonedFloor = randomFloor:Clone()
local timeLimit = clonedFloor:WaitForChild("TimeLimit").Value
clonedFloor.Parent = workspace
workspace:WaitForChild("DoorClosing"):Play()
openDoors()
wait(timeLimit)
workspace:WaitForChild("DoorClosing"):Play()
closeDoors()
randomMusic:Play()
clonedFloor:Destroy()
for i,v in pairs(plrs) do
v.Character:MoveTo(Vector3.new(-32.67, 7.331, 85.424))
v.Stats.Tokens.Value = v.Stats.Tokens.Value + 1
end
end

1 comment
If people are wondering what the solution was, I had to do table.remove(plrs, table.find(plrs, player))