(this was tested with two people)
What the script is supposed to do: Put everyone onto teams Red and Blue, and give them swords. It is also supposed to change them back to the players team on death, and once one team is out of players they all are changed back to the players team and it restarts
What is happening: Put one person on blue team, and give the person on players team a sword
I am fairly new to for loops so the odds are im doing something wrong. Anyway, does anyone know what is going wrong? And if so, how can i fix it?
Script:
gameon = false
game.Players.PlayerAdded:connect(function(startteam)
startteam.TeamColor = BrickColor.new("Eggplant")
end)
local function setgame()
local players = game.Players:GetPlayers()
local teams = {BrickColor.new("Really red"), BrickColor.new("Really blue")}
for key = 1, #players do
table.remove(players,math.random(#players)).TeamColor = teams[key % 2 + 1]
local player = table.remove(players, math.random(#players))
local tool = game.ServerStorage.ClassicSword
tool:Clone().Parent = player.Backpack
while gameon do
wait()
local bp = game.Teams.BlueTeam:GetChildren()
local rp = game.Teams.RedTeam:GetChildren()
if #bp == 0 then
for b = 1, #bp do
table.remove(bp).TeamColor = BrickColor.new("Eggplant")
end
gameon = false
end
if #rp == 0 then
for r = 1, #rp do
table.remove(rp).TeamColor = BrickColor.new("Eggplant")
end
gameon = false
end
end
end
end
while true do
wait()
if not gameon then
wait(10)
local players = game.Players:GetChildren()
if #players > 1 then
gameon = true
setgame()
end
end
end
game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
Character.Humanoid.Died:connect(function()
Player.TeamColor = BrickColor.new("Eggplant")
end)
end)
end) |