Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you check to see if randomly picked things arent repeating?[Solved]

I'm trying to make a script that picks two random things and then make sure they do not repeat. I currently have:

admin={"parkderp1","random","name"}
for i=2, do
pick=admin[math.random(1,#admin)]
wait(0.01)
print(pick)
end

Thats working i just dont know how to check if they repeat by repeating i mean the output being: parkderp1,parkderp1

1 answer

✓ Accepted answer

A really simple way is to keep re-picking until the choice is not what it was the time before, e.g.,

local previousChoice = nil

local list = {"abc","def", "ghi"}
while true do
	wait(1)
	local choice
	repeat
		choice = list[ math.random(1, #list) ]
	until choice ~= previousChoice
	previousChoice = choice

	print(choice)
end

Warning: If there's only one element in the list, this will cause an infinite loop.

1 comment

0

Thank you it seems to be working.

This discussion is preserved as it was. New answers, comments, and votes are closed.