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

How do I find a random child of something and use it?

So I want to find a child of a folder randomly and then use the position of that part. How would you do this?

So far I have:

local parts = game.Workspace.PartsModel:GetChildren()

Now I need to try find ONE child of that at random. How would I do this?

2 answers

✓ Accepted answer

Im writing this on my phone soo it might not be 100% right.

local randomchild = math.random(1,#parts) --choose random index number
parts[randomchild] --use that index number to get the instance with that number

If you have any problem with the code above Please tell me

We can use math.random() for this.

local Children = game.Workspace.PartsModel:GetChildren()
local RandomIndex = math.random(1, #Children)
local RandomChild = Children[RandomIndex]
print(RandomChild.Name)

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