How do I make the randomize not equal to other's

Role[Player] = Characters:GetChildren()[math.random(1, #Characters:GetChildren())]

	for _, v in Players:GetPlayers() do
		
		if v == Player then
			continue
		end
		
		if Role[Player] == Role[v] then
			Role[Player] = Characters:GetChildren()[math.random(1, #Characters:GetChildren())]
		end

	end

I tried to make it detect if other players have the same value than it re-rolls. But it isn’t working.

image

i would suggest to do a variable juste the line before Role[Player] with Characters:GetChildren() like:

local Chars = Characters:GetChildren()
Role[Player] = Chars[math.random(1, #Chars)]

Could do something like this instead:

local Pool = Characters:GetChildren()
for _, plr in Players:GetPlayers() do
    local ChosenIndex = math.random(#Pool)
    Role[Player] = Pool[ChosenIndex]
    table.remove(Pool, ChosenIndex)
end
1 Like