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

Can somebody help?

Asked by 10 years ago
team1 = game.Teams["Survivor"]--By CatAlpha,This is the secert "stuff" script.
team2 = game.Teams["Infected"]

Game.Players.PlayerAdded:connect(function(Player) 
    Player.CharacterAdded:connect(function(Character) 
        Character.Humanoid.Died:connect(function() 
             Player.TeamColor = team2.TeamColor 
        end)
    end)
end)


Just asking but does anybody know how to make 1 random player onto team two?

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Well first, you have to know some basic things about tables.

In a table, you can take the table's name followed by brackets and a number, and that gives you the value from the table corresponding to the number, like this:

MyTable = {"Hi","People","I'm","Perci1!"}
print(MyTable[1])
print(MyTable[3])

--output: Hi, I'm

Since you can get a value from a table with a number, if we get a random number it should give us a random value. For this we use math.random().

MyTable = {"Hi","People","I'm","Perci1!"}
randomNumber = math.random(1,#MyTable) --This will pick a random number between 1 and the number of values in the table.
randomValue = MyTable[randomNumber]
print[randomValue] --Will print a random value.

Now, we will talk about GetPlayers(). GetPlayers()converts all the player in the server into a table. Therefore we use the same method to get a random player as we used to get a random value.

players = game.Players:GetPlayers()
randomNumber = math.random(1,#players)
randomValue = players[randomNumber]
print(randomValue]

Hope i helped!

0
Wow this really did help,I really like when people actualy help me unstead of give me just a script. DerpTrollark 20 — 10y
Ad

Answer this question