Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I choose a random child of an object?

Asked by 10 years ago

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

Log in to vote
2
Answered by 10 years ago
local Lighting = game:GetService("Lighting")

local Map = Lighting:GetChildren()[math.random(1, #Lighting:GetChildren())]
Ad
Log in to vote
0
Answered by 10 years ago

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

Log in to vote
0
Answered by
piRadians 297 Moderation Voter
6 years ago
Edited 6 years ago
        math.randomseed(tick())
local maps = game.Lighting:GetChildren()
print(maps[math.random(1,#maps)])

Answer this question