I'm working on a project that chooses a random item in a group of items often. However, most of the time, they aren't just picking one, they are picking multiple. So, I've been settling this with this solution:
local spotter1 = AllPlayers[math.random(1, #AllPlayers)]
local spotter2 = AllPlayers[math.random(1, #AllPlayers)]
local spotter3 = AllPlayers[math.random(1, #AllPlayers)]
local spotter4 = AllPlayers[math.random(1, #AllPlayers)]
if spotter2 == spotter1 then
repeat
spotter2 = AllPlayers[math.random(1, #AllPlayers)]
until spotter2 ~= spotter1
end
if spotter3 == spotter1 or spotter3 == spotter2 then
repeat
spotter3 = AllPlayers[math.random(1, #AllPlayers)]
until spotter3 ~= spotter1 and spotter3 ~= spotter2
end
if spotter4 == spotter1 or spotter4 == spotter2 or spotter4 == spotter3 then
repeat
spotter4 = AllPlayers[math.random(1, #AllPlayers)]
until spotter4 ~= spotter1 and spotter4 ~= spotter2 and spotter4 ~= spotter3
end
It basically makes sure that the item picked is not the same as the second item picked so that we get 4 of different items. However, this obviously takes up a lot of code, and my game is already having trouble with working with hundreds of lines of code, so I want to make things simpler for the computer to read and pick things. Is there a better way to do this?

3 comments
Make a table, and remove the players that were already the spotters. When it's empty or the game is over, just reset the table.
Oh i get it
Thank you!