Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Put player into a random team?

Asked by 7 years ago

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

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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
0
Messor you still go on this website? WHAT?! EzraNehemiah_TF2 3552 — 7y
0
Yes MessorAdmin 598 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
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

Answer this question