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 choose a random child of an object?

I have a game, and I want it to choose a random model that is in Lighting. How would I go about doing this?

3 answers

✓ Accepted answer
local Lighting = game:GetService("Lighting")

local Map = Lighting:GetChildren()[math.random(1, #Lighting:GetChildren())]

I would use a loop (:GetChildren) and then use math.random for every loop cycle.

		math.randomseed(tick())
local maps = game.Lighting:GetChildren()
print(maps[math.random(1,#maps)])

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