Currently I have been trying to make a script where a table gets looped through and out of that table 1 value gets picked randomly. Instead, I get 3 values! I only want 1 value to appear. I tried searching for this problem but did not find an answer. The problems were similar, but not exact.
Here is the script:
local vegetables = {"Carrots", "Potatos", "Salad"}
for index = 1, #vegetables do
local random = vegetables[math.random(1, #vegetables)]
print(random)
end
If I’m understanding correctly, you’re getting three different printed lines. That’s because you’re using a for loop which does the random picker 3 times. You can have it do it once by removing the for loop.