How would I ensure that the two items picked are not the same?

Hey guys, so I am making a map voting thing. Similar to the voting gui in the car crushers 2 derby mode, I have got this code:

--events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local info2 = ReplicatedStorage:WaitForChild("info2")
local info1 = ReplicatedStorage:WaitForChild("info1")
--stuff
while wait(1) do
	local items = script.Parent.maps:GetChildren()
	local randomItem = items[math.random(1, #items)]
	local randomItem2 = items[math.random(1, #items)]

	--code
	if randomItem == randomItem2 then
		repeat
			local randomItem2 = items[math.random(1, #items)]
			wait()
		until randomItem ~= randomItem2
	end
	print(randomItem.Name, randomItem2.Name)
end

As you can tell it prints the chosen items every second. I think I can get the system that sends the information to the clients, but if not you will see me here again. The output will sometimes print the same names, for example:

map1 map1

I do have a picture of the output and I can attach it if you want but I don’t think that that is important.
The script works, just not how I intend for it to work

if randomItem ~= randomItem2 then

This checks if randomItem1 is not equal (~= operator) to randomItem2

repeat
	local randomItem2 = items[math.random(1, #items)]
	wait()
until randomItem ~= randomItem2

Take out the local, you’re creating a new variable that the print statement can not see

Should just be:

repeat
	randomItem2 = items[math.random(1, #items)]
	wait()
until randomItem ~= randomItem2
2 Likes

Yes I know that, that may be the problem

Thanks, at least my problems are easy to fix.