Use math.random to For A Frames Children

Hey! I Am Trying to Learn About math.random Today. Iv Ran into An Issue Tho.

How can I Use math.Random on A Frames Children?
Suppose I Have A lot of Image Labels Inside a Frame, Each Label with A Different Name
How Could I Print A Random Image Label’s Name Which Are Parented to the Frame?

You can generate a random number between 1 and the array length, then, access the index.

local children = frame:GetChildren()  -- returns an array with the children (numbered index)
local random_index = math.random(#children)  -- returns a random number between 1 and the array length

local random_child = children[random_index]
print(random_child:GetFullName())
2 Likes