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 create a script that gets a random child?

How do I create a :GetChildren() that randomly picks a child?

1 comment

2

:GetChildren() returns a table of all the children, so you could do something like thing:GetChildren()[math.random(1, #thing:GetChildren())] which would give you a random child.

1 answer

✓ Accepted answer
parent = workspace.Model

local rng = math.random(1, #parent:GetChildren())

rng is a random number between 1 and the amount of children the instance has.

If an instance has 5 children, it will be a number from 1 to 5.

With this we can select a random child from the instance.

local child = parent:GetChildren()[rng]

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