--Not the full script local Players = {} local Zombies = {} for i,v in pairs(players:GetPlayers()) do table.insert(Players,v.Name) end table.insert(Zombies ,(Players[math.random(#Players)]))
Depending on how many players there are, a certain amount of players get chosen to be zombies. The problem I am facing is that sometimes the same player gets chosen twice. How would I prevent this?
All you have to do is just remove the player from the table once they're chosen.
local chosenPlayerIndex = math.random(#Players) table.insert(Zombies, Players[chosenPlayerIndex]) table.remove(Players, chosenPlayerIndex)
thebayou has a working way, otherwise u can make a variable with the last player that got choosen and then a if function that checks if the last player is the same as the one that got choosed before and if it did you just randomize again