I am making a swords vs guns game and it wont change the teams. Here is the script
--Variables--
local Teams = game:GetService("Teams"):GetChildren()
local TextBox = script.Parent
--Variables--
--Funtions--
function GenorateTeam()
for i, player in pairs(game.Players:GetPlayers() ) do
if player then
if player.Team == nil then
local randomteam = Teams[math.random(1, #Teams)]
player.Team = randomteam
GameText2()
end
end
end
end
function GameText()
for i = 30, 0, -1 do
print(i.. "one")
TextBox.Text = "Game Starting in ".. i
wait(1)
print("waited")
end
TextBox.Text = "Randomizing teams"
GenorateTeam()
end
function GameText2()
wait(2)
TextBox.Text = "Plugging group"
wait(0.5)
TextBox.Text = "JOIN NOW"
wait(0.01)
TextBox.Text = "Giving gears"
wait(2)
game.Teams.ClassicSword.Parent = game.Teams.Melee
game.Teams.Handgun.Parent = game.Teams.Gunners
end
GameText()
The text label just stops on “Randomizing Teams…”
local randomteam = Teams[math.random(1, #Teams)]
player.Team = Teams[randomteam]
The Reason is not working is because you are trying to set a Player’s Team to a number and not a Team. #Teams just simply gets the number of all the Items in the Table.
local TeamsTable = {}
table.insert(TeamsTable, Teams) -- Inserts all Teams into a Table for use
function GenorateTeam()
for i, player in pairs(game.Players:GetPlayers() ) do
if Player.Team == nil then
local randomteam = TeamsTable[math.random(1, #TeamsTable)]
player.Team = TeamsTable[randomteam]
GameText2()
end
end
end
function GenorateTeam()
for i, player in pairs(game.Players:GetPlayers() ) do
if player then
if player.Team == Teams.Neutral then
player.Team = Teams:GetTeams()[math.random(1, #Teams:GetTeams()]
GameText2()
end
end
end
end