Why is this happening?

Hey i came on here today because i dont know why there is more then 1 things in the table.

local function shuffleColors()
	for Index = 1, #CharactersFolder do
		RandomIndex = CharactersFolder[math.random(1, #CharactersFolder)]
		
		if not table.find(ShuffledTable, RandomIndex) then
			table.insert(ShuffledTable , RandomIndex)
		end
	end
	
	return RandomIndex
end

here is the code (inside the charactersfolder is just values)

1 Like

what exactly are you trying to achieve here ?

3 Likes

basically i want each player that joins the game to get a random color but if he gets a color randomly that another player in the game has then it would just pick another random color. and when they leave the game there color will be removed from the table (hopefully this makes sense and i do this all with that functionh)

you can use this

local ColorTable = {}
local PlayerColors = {}

local function PickColor(Player)
if #ColorTable == 0 then return end
local num = math.random(#ColorTable)
local Color = ColorTable[num]
table.remove(ColorTable, num)
PlayerColors[Player] = Color
return Color
end

local function PlayerRemoving(Player)
if PlayerColors[Player] then
table.insert(ColorTable, PlayerColors[Player])
PlayerColors[Player] = nil
end
end
1 Like

thank you ill try it out!

30 ch_aracters

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.