im basically making a team round based system like csgo/valorant
I need help with the part where when the round starts, this script on the serverscriptservice could constantly detect if a team ends up with 0 players to attribute the victory to the opposing team
script below
– Variables
local Teams = game:GetService(“Teams”)
local team1 = Teams.BlueTeam
local team2 = Teams.RedTeam
local Players = game:GetService(“Players”)
local blueTeamPlayers = {}
local redTeamPlayers = {}
function respawnPlayers()
for _, player in ipairs(game.Players:GetPlayers()) do
if player.TeamColor == BrickColor.new(“Bright blue”) or player.TeamColor == BrickColor.new(“Bright red”) then
player:LoadCharacter()
end
end
end
– Start game
local function startGame()
for _, player in pairs(game.Players:GetPlayers()) do
if player.Team == team1 then
table.insert(blueTeamPlayers, player)
elseif player.Team == team2 then
table.insert(redTeamPlayers, player)
end
end
if #blueTeamPlayers < 1 or #redTeamPlayers < 1 then
print("No enough players to start the game.")
return
end
print("Iniciando o jogo...")
if #Teams.BlueTeam:GetPlayers() == 0 then
print("Red Team won.")
respawnPlayers()
elseif #Teams.RedTeam:GetPlayers() == 0 then
print("Blue Team won.")
respawnPlayers()
end
-- End
print("Round ended.")
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if player.Name == "DenysMilitar" and message:lower() == "start" then
startGame()
end
end)
end)