I'm trying to make a script that will put the player on a random team, but I can't exactly figure it out. There are two teams, Bright red and Bright blue.
This is what I have:
local teams = {"Bright blue","Bright red"} for _, player in pairs(game.Players:GetChildren()) do player.TeamColor = player.TeamColor.new(math.random) end
GIF proving this code works. http://imgur.com/Io97MhX
local Teams, Players, Nothing, Runservice ={ {"Team1", "Really blue"}; {"Team2", "Really red"}; }, game:GetService("Players"), math.randomseed(tick()), game:GetService("RunService") function change_teams() for _,p in next,Players:GetPlayers() do local cTeam =Teams[math.random(1, #Teams)] -- Teams[1] or Teams[2] local Player =p Player.TeamColor =BrickColor.new( cTeam[2] ) -- cTeam[2] = a color print(p.Name.."'s name is now "..cTeam[1]) end end if Runservice:IsStudio() then print("Your in studio! I need to wait until the game is done loading!") repeat wait() until game.Loaded workspace:WaitForChild(game.Players.LocalPlayer.Name) end print("Game loaded! I will start my loop!") while true do change_teams() wait(5) end
function auto() P = game.Players NumP = game.Players.NumPlayers for _, red in pairs(P:GetPlayers()) do numred = red[math.random(1,NumP)] numred.TeamColor = BrickColor.new("Bright red") end for _, blue in pairs(P:GetPlayers()) do if blue.TeamColor ~= BrickColor.new("Bright red") then blue.TeamColor = BrickColor.new("Bright blue") end end end