Tables not working properly?

What I would like to achieve, I would like to achieve the game adding 3 taggers, in my freeze tag game.

My problems, is that whenvever i add taggers i choose a random number within the availablePeople table which is a copy of a other table i had which were a table with all the players in, then what it does is that it find 3 random people then doing all of the stuff it removes the person from the availablePeople to not get chosen again. But the problem is ive tried debugging this but it looks like it removes from both of the players and availablePeople which is the only table it should be removed from am I doing something wrong, or is it just me not seing it?

Ive already tried looking for information on the Devforum, but theres no Solutions I could find.

You dont have to rewrite it all, I just need to know whats wrong.

				
local availablePeople = {}
				
availablePeople = players
				
for i = 1,3,1 do 
					
	local chosenPos = math.random(1,#availablePeople)
	local chosenPlayer = availablePeople[chosenPos]
					
	chosenPlayer.Team = game.Teams.Taggers
	chosenPlayer.TeamColor = game.Teams.Taggers.TeamColor
					
	local hitArea = InGameObjectsFolder.HitArea:Clone()
	local weld = Instance.new("Weld",chosenPlayer.Character.HumanoidRootPart)
	weld.Part0 = hitArea
	weld.Part1 = chosenPlayer.Character.HumanoidRootPart
	hitArea.Parent = chosenPlayer.Character
					
	table.remove(availablePeople,chosenPos)
	warn(availablePeople)
end
	
Values.AmountTaggers.Value = 3

Sorry if this is not what you want, but wouldn’t it be better to just choose 3 people from game.Players and then make an array with the 3 chosen players in there. Then next time you run it you check if they are the same and if they are the same you choose it again for just that one (probably have a new function that is called ChoosePlayer(). Not sure if this helps.

I’ll try this soon thanks for your respond.

local players = game:GetService("Players")
local availablePeople = players:GetChildren()

This is how you’d get a table of all current players.

I already did this at the start of the round, I’ve made a table named players with all the players then I created a copy of it named available people but somehow it changed both tables?

your problem with changing players and availablepeople is that, they are the same.
you didn’t make a new table here, let me add notation to what you did to let it make sense.

local availablePeople = {} --Creation of new, empty table filling the variable.
				
availablePeople = players --Overwriting the freshly made table with the already existing one, making this variable go to that existing table

you can create a clone of the table by doing this

local availablePeople = {table.unpack(players)} --Makes a new, empty table, then fills it with the *Contents* of the already existing table.

table.unpack() returns all of the values of a table, so doing something like:

local array = {1, 2, 3} --Creating a new table, and filling it with 1, 2 and 3.
local a, b, c = table.unpack(array) --Creates 3 variables, a = 1, b = 2, and c = 3.
print(a, b, c) --Prints 1, 2, 3

Thanks for the solution! It worked out.