Hi, I don’t understand why the code inside Promise.fromEvent isn’t called. I want to make it display Teleporting when players start teleporting
local LobbyTimers = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
local Promise = require(ReplicatedStorage.Libs.Promise)
local LobbyConfig = require(script.Parent.LobbyConfig)
local LobbyAnimationTimers = require(script.Parent.LobbyAnimationTimers)
local LobbyService = nil
local function updateCountdownText(countdown, seconds)
countdown.Text = seconds > 0 and `Start in {seconds}` or ""
end
local function shouldStopCountown(slotData)
return slotData.countdownToStart < 1 or #slotData.players == 0
end
function LobbyTimers.start(slot)
local slotData = LobbyService.getLobbySlot(slot)
local countdown = slotData.countdownObject
slotData.countdownToStart = LobbyConfig.COUNTDOWN_DURATION_SECONDS
task.spawn(function()
while not shouldStopCountown(slotData) do
updateCountdownText(countdown, slotData.countdownToStart)
local elapsed = 0
while elapsed < LobbyConfig.TIMER.COUNTDOWN_STEP do
task.wait(LobbyConfig.TIMER.CHECK_DELAY)
elapsed += LobbyConfig.TIMER.CHECK_DELAY
if shouldStopCountown(slotData) then
break
end
end
slotData.countdownToStart -= LobbyConfig.TIMER.COUNTDOWN_STEP
end
if slotData.countdownToStart <= 1 then
local success, result = pcall(function()
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ShouldReserveServer = true
return TeleportService:TeleportPartyAsync(LobbyConfig.GAME_PLACE_ID, slotData.players, teleportOptions)
end)
if success then
countdown.Text = "Teleporting..."
local promises = {}
Promise.each(slotData.players, function(player)
LobbyService.sendTogglePlayerLobbyGui(player, false)
local promise = Promise.fromEvent(player.OnTeleport, function(state)
if state ~= Enum.TeleportState.Failed then
slotData.players[player] = nil
end
end)
table.insert(promises, promise)
end)
Promise.all(promises):andThen(function()
if #slotData.players == 0 then
LobbyAnimationTimers.startWaitingForPlayers(slot)
return
else
for _, player in pairs(slotData.players) do
LobbyService.leavePlayer(player)
end
end
slotData.players = {}
end):catch(function()
warn("Failed to promise players!")
end)
else
warn(result)
end
end
LobbyAnimationTimers.startWaitingForPlayers(slot)
end)
end
function LobbyTimers.init(lobbyService)
LobbyService = lobbyService
end
return LobbyTimers