Choosing random value from table gives nil rather than name

Hi, I am trying to have a function choose a random character that the player will play from a table. Instead of getting the name, I get nil. Here is my code:

local availableCharacters = {}

function module.MoveAvailableCharacters()
	for i, v in pairs(game.ReplicatedStorage.AvailableCharacters:GetChildren()) do
		table.insert(availableCharacters, v.Name)
		
	end
end

function module.ChooseCharacterTest()
	for i, v in pairs(game.Players:GetPlayers()) do
		local randomCharacter = math.random(1, #availableCharacters)
		local chosenCharacter = table.find(availableCharacters, randomCharacter)
		
		print(chosenCharacter)
		
		v:FindFirstChild("Character").Value = tostring(chosenCharacter)
		
		table.remove(availableCharacters, randomCharacter)

		
	end
end
1 Like

Instead of using table.find, why can’t you use
local chosenCharacter = availableCharacters[randomCharacter]

2 Likes

I overthought it and didn’t think about that (even though I knew about that). Question, with the first function, will it automatically remove everything in it or will it just continue adding?

EDIT: It does, I’ll need to remove the stuff inside of it.

1 Like