I'm trying to have the game select two children from a model. I want it to select one, then select a different one (such as two flavors of tea). The script for choosing the first works perfectly, but then I have it chose a second item using a Repeat (in case it chooses the first object again, as I want two unique choices). However, the chosen2 variable is 'nil' when I ask it to print after 'until.' I feel like I may be missing something obvious here but I'm not sure. Any explanation for this?
function Choose2 (Chosen1)
print (Chosen1) --prints the name of the first chosen object fine, such as "Peppermint"
repeat
local Chosen2 = (Items[math.random(1,#Items)])
print(Chosen2) -- prints the name of the second chosen object fine, such as "Earl Grey"
until Chosen2 ~= Chosen1
print (Chosen2) -- prints nil
end

1 comment
Why make it so complicated? I see what you're trying to do. You dont want them to be equal but why dont you remove the chosen1 out of the table then? This way it would remove 1 item from the table ( chosen1 ) and chosen2 could never take the same as chosen1 because it is not in the table anymore.