Trying to use Repeat

Im Trying to get a certain number:10
Im also using a Table with numbers in it.
Im Using Math.Random to have a random possibility to print a range of numbers in the table.
Hers the code but i want it to keep Using Math.Random until the Number 10 Gets Selected:

local Nums = {1,2,3,4,5,6,7,8,9,10}
local ChosenNum = Nums[math.random(1,#Nums)]

repeat Print(ChosenNum) until ChosenNum == 10

You’re only calling math.random once. ChosenNum doesn’t change.

How Can i Call It More than Once Then?

Code inside the loop runs more than once. Code outside of the loop runs once. If you call math.random inside the loop then each time it is called, it will return another random number.

1 Like

Isnt the Print(ChosentNum) in the Loop? And What would be in the loop

You would do something like

local Nums = {1,2,3,4,5,6,7,8,9,10} 

repeat
     local ChosenNum = Nums[math.random(1,#Nums)] 
     print(ChosenNum) 
until ChosenNum == 10

Your issue was that you didn’t re-select the Chosen Number after printing it.

Everything inbetween repeat and until will keep repeating until the condition is met, while everything else won’t.

2 Likes

Thank You. Now ill know now on.