I’m trying to make a system where whenever all the players are in the “lobby” team it makes the timer go down to 5 seconds but whenever it happens the script does nothing
btw the script is in workspace
local players = game.Teams.Lobby:GetPlayers()
while wait() do
for _, plr in pairs(players) do
if #players == game.Workspace.ServerStats.NumberOfPlayers.Value and game.Workspace.Time.InLobby == false then
print("Ended Round Early!")
game.Workspace.Time.Value = 5
end
end
end
The players never gets updated as it’s not in the loop, also break the loop after so it does not cause performance issues:
while wait() do
local players = game.Teams.Lobby:GetPlayers()
for _, plr in pairs(players) do
if #players == game.Workspace.ServerStats.NumberOfPlayers.Value and game.Workspace.Time.InLobby == false then
print("Ended Round Early!")
game.Workspace.Time.Value = 5
break
end
end
end
--// Services
local Players = game:GetService("Players")
local function GetPlayersInLobby()
local Result = {}
local PlayersTable = Players:GetPlayers()
for _, v in PlayersTable do
if v.Team.Name == "Lobby" then -- Change the string to the team name
table.insert(Result, v)
end
end
return Result
end
while task.wait(1) do
if #GetPlayersInLobby() == game.Workspace.ServerStats.NumberOfPlayers.Value and game.Workspace.Time.InLobby == false then
print("Ended Round Early!")
game.Workspace.Time.Value = 5
end
end
while wait(.1) do
local players = game.Teams.Lobby:GetPlayers()
for _, plr in pairs(players) do
if #players == game.Workspace.ServerStats.NumberOfPlayers.Value and game.Workspace.Time.InLobby.Value == false and debounce == false and not (game.Workspace.Time.Value == 120) then
debounce = true
print("Ended Round Early!")
game.Workspace.Time.Value = 5
wait(12.5)
debounce = false
end
end
end