Answered by
4 years ago Edited 4 years ago
You need to remove the element from the table
after you've selected it. Take this analogy as an example; you've entered a lottery, but when you win your name doesn't get removed, the paper note with your name written on it gets thrown back into the hat again. That means you still have a chance of winning again.
table.remove(table, index)
will do the job for you. It'll remove the element you want gone and it will push the other elements forwards so there won't be a gap. It'll still work with ipairs
.
Teamfolder[index] = nil
will also remove the element, but it'll leave a gap in the table
, and will now not work with ipairs
.
But since you're not using ipairs
here, either should do the trick for you.
01 | local Teamfolder = { workspace.Team 1 , workspace.Team 2 , workspace.Team 3 , workspace.Team 4 } |
06 | local index = math.random( 1 ,#Teamfolder) |
07 | currentteam = Teamfolder [ index ] |
08 | print (currentteam.Name.. " was chosen for this round." ) |
09 | currentteam.Parent = game.Teams |
10 | table.remove(Teamfolder, index) |