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

How do I make this.....

Asked by 10 years ago

I am not asking for a script so please donĀ“t get angry at me and start yelling me things, I am trying to learn, Lualearnes is down so this is the only well-known resource I use to learn things, know getting over my doubt how do I make a script that will only choose 3 people out of 10 randomly I only have one part of the script here it is

players = game.Players:GetPlayers ()
infected = players[math.random (1, #NumPlayers)]

1 answer

Log in to vote
1
Answered by
trogyssy 221 Moderation Voter
10 years ago
math.randomseed(tick())--This makes random numbers more random for the rest of the script
players = game.Players:GetPlayers() --No space between the method and the arguments
infected = {players[math.random(1, #NumPlayers)]}--This makes a table with one of your three in it already

repeat--A simple repeat to make sure the same person isn't added to the list of infecteds twice
one=players[math.random(1, #NumPlayers)]
until one~=infected[1]
table.insert(infected, 2, one)--The table that is being added to is "infected", the position of the new item is two, and the item being added is our pre-established variable "one"

repeat--Now let's do the same thing for the other one being added
two=players[math.random(1, #NumPlayers)]
until two~= infected[1] and two~= infected[2] --This is the main difference between our two repeats. This one has two items to check rather than one, so we use "and" to check both.
table.insert(infected, 3, two)

Not as efficient as it could be, but here ya go :)

Ad

Answer this question