I know this is a request, but I'm confused/wondering if there is a way to scramble a certain amount of random players on a certain team.
For instance, if you were making a zombie game where at the start there would be more zombies than humans, and the server consisted of 25 players, you want there to be more players than zombies. Of course, you could use math, but you would rather get it straight to the point rather than use formulas. For instance, on the game, you would like to have 20 random players be zombies, have have 5 random players be humans. Is there a way to do this? And if so, could someone please tell and explain it to me?
If you know the number of players, you can just get 5 random players;
local players = game.Players:GetPlayers() local playerList = {} for i = 1,5 do local chosen = players[math.random(#players)] table.insert(playerList, chosen) end
Then just make everyone else a zombie.
Although you would probably want to write a function to make sure a player isn't already in the table
function IsInTable(value, array) for i,v in pairs(array) do if v == value then return true end end end
But you won't know how many players are in the server, so you'd have to do math. If you want, say, 3x the amount of zombies as players, just divide the number of players in the game by 3, then choose that amount of players.
local players = game.Players:GetPlayers() local playerList = {} local playerNumber = math.ceil(game.Players.NumPlayers/3) --We use math.ceil just in case the number of players isn't divisible by 3. for i = 1, playerNumber do local chosen = players[math.random(#players)] table.insert(playerList, chosen) end