For some reason after a player leaves in a lobby (has an array) the proximity prompts I use to let players enter an exit don’t work, I’ve tried to see if the array is affected but it doesn’t let me. What happens is when someone leaves in the lobby everything happens like I want it but, players wont get teleported to the waiting room. It partially works because the proximity prompt changes to leave once the enter one is activated but the player isn’t teleported.
This is my code:
local entered = {}
local gui = game.Workspace.Exit.gui.BillboardGui.Frame
local RemoteEvent = game.ReplicatedStorage.Lobby
local timer = Instance.new("NumberValue")
timer.Value = 10
local vtimer = gui.timer
local teleporting = Instance.new("BoolValue")
teleporting.Value = false
local vteleporting = gui.status
vteleporting.Text = " "
local TeleportService = game:GetService("TeleportService")
local placeid = 8964283433
if not game:GetService("RunService"):IsStudio() then
local ReservedServerCode = TeleportService:ReserveServer(placeid)
end
game.Players.PlayerRemoving:Connect(function(player)
if table.find(entered, player) then
table.remove(entered, table.find(entered, player))
end
end)
timer:GetPropertyChangedSignal("Value"):Connect(function()
if timer.Value < 1 then
teleporting.Value = true
vteleporting.Text = "Teleporting..."
else
teleporting.Value = false
vteleporting.Text = " "
end
end)
teleporting:GetPropertyChangedSignal("Value"):Connect(function()
if teleporting.Value == true then
if not game:GetService("RunService"):IsStudio() then
TeleportService:TeleportToPrivateServer(placeid, ReservedServerCode, entered)
entered = {}
gui.players.Text = "Players: " ..#entered
else
print("Teleporting")
end
end
end)
RemoteEvent.OnServerEvent:Connect(function(player, request)
if request == "Enter" then
player.Character.HumanoidRootPart.CFrame = game.Workspace.Exit.gui.CFrame
table.insert(entered, player)
else
player.Character.HumanoidRootPart.CFrame = game.Workspace.leavepart.CFrame
for index = #entered, 1, -1 do
if entered[index] == player then
table.remove(entered, index)
end
end
end
gui.players.Text = "Players: "..#entered
end)
while true do
task.wait()
if #entered > 0 then
while timer.Value > 0 and #entered > 0 do
task.wait(1)
timer.Value -= 1
vtimer.Text = "Timer: " .. timer.Value
end
else
timer.Value = 10
vtimer.Text = "Timer: " .. timer.Value
end
end
And this is the code for the client sided script for the prompts. (In stater player scripts):
local RemoteEvent = game.ReplicatedStorage.Lobby
local enterprompt = game.Workspace.Walls["lobby wall"].Enterlobby
local leaveprompt = game.Workspace.Walls["lobby wall"].Leavelobby
enterprompt.Triggered:Connect(function(Player)
enterprompt.Enabled = false
leaveprompt.Enabled = true
RemoteEvent:FireServer("Enter")
end)
leaveprompt.Triggered:Connect(function(Player)
enterprompt.Enabled = true
leaveprompt.Enabled = false
RemoteEvent:FireServer("Leave")
end)
I don’t know why it breaks, please help.