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

Assigning Players to teams randomly?

Asked by 9 years ago

Hey, i've attempted at a script to create two teams then randomly assign players to teams. Currently i tried to make it so that it creates a NumberValue in every player then randomly generates a number between 1 and 2 and if its 1 your on team A if 2 team B. Heres my script.

P = game.Players:GetPlayers()
E = Instance.new("NumberValue")
E.Parent = game.Players:GetPlayers()
E.Value = math.random(1,2)
if E.Value == 1 then
    E.Parent.Parent.Team = game.Teams.Guards
end
if E.Value == 2 then
    E.Parent.Parent.Team = game.Teams.Theives
end

BTW this is the section of the script that doesnt work, creating the teams works fine. Returns error "Expected Object got Table" probably caused by me trying to put a Instance in a table, but im not sure how to fix this.

Thanks! -Sir

0
Hold on I got the answer, give me a second NinjoOnline 1146 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
players = game.Players:GetChildren()
teams = {"Bright blue","Bright red"}
num = 1
for i,v in pairs(players) do
    v.TeamColor = BrickColor.new(teams[num])
    num = num + 1
    if num > #teams then
        num = 1
    end
end

The above will sort two teams out and give them either blue or red team.

Now you want a team with guards and thieves. Just put this is at the same point you had yours, then make 2 teams in the folder, 1 bright blue, 1 bright red, then rename the team names to Guards/Thieves.

If this dosent work then please tell me and I will look over and see if I got anything wrong. If this did help then remember to upvote and accept answer for others to see if they have the same problem.

  • NinjoOnline
0
What exatly do you mean by put 2 teams in "the folder" what is "the folder" SirKitten2000 0 — 9y
0
There should be a folder in Explorer called 'Teams' NinjoOnline 1146 — 9y
0
ok SirKitten2000 0 — 9y
Ad

Answer this question