I want to achieve that the last team which has players in it wins, and gets the reward.
I already made the team creating and dividing players into the team. I also tried to create a block of code that should end the round when all the other teams players are 0 and give the winning team the rewards. But this doesnt work, maybe someone can help me with this?
elseif map:FindFirstChild("Teams4") then
roundType = "Teams4"
local players = game.Players:GetPlayers()
local redteam = Instance.new("Team")
local blueteam = Instance.new("Team")
local yellowteam = Instance.new("Team")
local greenteam = Instance.new("Team")
local dead = Instance.new("Team")
redteam.Name = "Red"
blueteam.Name = "Blue"
yellowteam.Name = "Yellow"
greenteam.Name = "Green"
dead.Name = "Dead"
redteam.TeamColor = BrickColor.new("Really red")
blueteam.TeamColor = BrickColor.new("Deep blue")
yellowteam.TeamColor = BrickColor.new("New Yeller")
greenteam.TeamColor = BrickColor.new("Forest green")
dead.TeamColor = BrickColor.new("Mid gray")
redteam.Parent = game.Teams
blueteam.Parent = game.Teams
yellowteam.Parent = game.Teams
greenteam.Parent = game.Teams
dead.Parent = game.Teams
local t = 1
local Teams = {game.Teams.Red,game.Teams.Blue,game.Teams.Green,game.Teams.Yellow}
for i,v in pairs(game.Players:GetPlayers()) do
if t == 1 then
v.Team = Teams[1]
t = 2
elseif t == 2 then
v.Team = Teams[2]
t = 3
elseif t == 3 then
v.Team = Teams[3]
t = 4
elseif t == 4 then
v.Team = Teams[4]
t = 1
end
for _, player in pairs(game:GetService("Players"):GetChildren()) do
local char = player.Character
connection = char:WaitForChild("Humanoid").Died:Connect(function()
print(player.Name .. " has died!")
v.Team = dead
connection:Disconnect()
end)
end
end
local children = workspace.Ingame:GetChildren()
for i = 1,#children do
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
end
map:FindFirstChildWhichIsA("Tool"):Destroy()
if roundType == "Teams4" then
repeat roundLenght = roundLenght -1
status.Value = "Time left: "..roundLenght
task.wait(1)
until roundLenght == 0 or
redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 or
blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 or
redteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 or
redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0
if redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 then
status.Value = "Winner: "..greenteam.Name
elseif blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 then
status.Value = "Winner: "..redteam.Name
elseif redteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 then
status.Value = "Winner: "..blueteam.Name
elseif redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 then
status.Value = "Winner: "..yellowteam.Name
end
redteam:Destroy()
blueteam:Destroy()
yellowteam:Destroy()
greenteam:Destroy()
dead:Destroy()
end
end
