How To Fix Dupe Random Selecting

Hi, Im Creating a system to remove dupe stages, its looks like this


local randomIndex = math.random(1, #Stages)
			if not table.find(usedStages, randomIndex) then
				selectedStage = Stages[randomIndex]:Clone()
				table.insert(usedStages, selectedStage)
				print(usedStages)
			end
end

Its Must Checking if random selected stage in the table, and if stage not in table, then add it, but if in table then it will select again

Replace with

local randomIndex = math.random(1, #Stages)
if not usedStages[Stages[randomIndex]] then
selectedStage = Stages[randomIndex]:Clone()
table.insert(usedStages, selectedStage)
print(usedStages)
end
end

should work hopefully